1 /* Process declarations and variables for C++ compiler.
2 Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
5 Contributed by Michael Tiemann (tiemann@cygnus.com)
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
14 GCC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
24 /* Process declarations and symbol lookup for C++ front end.
25 Also constructs types; the standard scalar types at initialization,
26 and structure, union, array and enum types when they are declared. */
28 /* ??? not all decl nodes are given the most useful possible
29 line numbers. For example, the CONST_DECLs for enum values. */
33 #include "coretypes.h"
38 #include "tree-iterator.h"
39 #include "tree-inline.h"
50 #include "diagnostic.h"
54 #include "tree-flow.h"
55 #include "pointer-set.h"
56 #include "splay-tree.h"
59 static tree grokparms (tree parmlist, tree *);
60 static const char *redeclaration_error_message (tree, tree);
62 static int decl_jump_unsafe (tree);
63 static void require_complete_types_for_parms (tree);
64 static int ambi_op_p (enum tree_code);
65 static int unary_op_p (enum tree_code);
66 static void push_local_name (tree);
67 static tree grok_reference_init (tree, tree, tree, tree *);
68 static tree grokvardecl (tree, tree, const cp_decl_specifier_seq *,
70 static void record_unknown_type (tree, const char *);
71 static tree builtin_function_1 (tree, tree, bool);
72 static tree build_library_fn_1 (tree, enum tree_code, tree);
73 static int member_function_or_else (tree, tree, enum overload_flags);
74 static void bad_specifiers (tree, const char *, int, int, int, int,
76 static void check_for_uninitialized_const_var (tree);
77 static hashval_t typename_hash (const void *);
78 static int typename_compare (const void *, const void *);
79 static tree local_variable_p_walkfn (tree *, int *, void *);
80 static tree record_builtin_java_type (const char *, int);
81 static const char *tag_name (enum tag_types);
82 static tree lookup_and_check_tag (enum tag_types, tree, tag_scope, bool);
83 static int walk_namespaces_r (tree, walk_namespaces_fn, void *);
84 static void maybe_deduce_size_from_array_init (tree, tree);
85 static void layout_var_decl (tree);
86 static tree check_initializer (tree, tree, int, tree *);
87 static void make_rtl_for_nonlocal_decl (tree, tree, const char *);
88 static void save_function_data (tree);
89 static void check_function_type (tree, tree);
90 static void finish_constructor_body (void);
91 static void begin_destructor_body (void);
92 static void finish_destructor_body (void);
93 static tree create_array_type_for_decl (tree, tree, tree);
94 static tree get_atexit_node (void);
95 static tree get_dso_handle_node (void);
96 static tree start_cleanup_fn (void);
97 static void end_cleanup_fn (void);
98 static tree cp_make_fname_decl (location_t, tree, int);
99 static void initialize_predefined_identifiers (void);
100 static tree check_special_function_return_type
101 (special_function_kind, tree, tree);
102 static tree push_cp_library_fn (enum tree_code, tree);
103 static tree build_cp_library_fn (tree, enum tree_code, tree);
104 static void store_parm_decls (tree);
105 static void initialize_local_var (tree, tree);
106 static void expand_static_init (tree, tree);
108 /* The following symbols are subsumed in the cp_global_trees array, and
109 listed here individually for documentation purposes.
112 tree wchar_decl_node;
114 tree vtable_entry_type;
115 tree delta_type_node;
116 tree __t_desc_type_node;
118 tree class_type_node;
119 tree unknown_type_node;
121 Array type `vtable_entry_type[]'
124 tree vtbl_ptr_type_node;
131 A FUNCTION_DECL which can call `abort'. Not necessarily the
132 one that the user will declare, but sufficient to be called
133 by routines that want to abort the program.
137 The FUNCTION_DECL for the default `::operator delete'.
139 tree global_delete_fndecl;
142 tree type_info_type_node, tinfo_decl_id, tinfo_decl_type;
143 tree tinfo_var_id; */
145 tree cp_global_trees[CPTI_MAX];
147 /* Indicates that there is a type value in some namespace, although
148 that is not necessarily in scope at the moment. */
150 tree global_type_node;
152 /* The node that holds the "name" of the global scope. */
153 tree global_scope_name;
155 #define local_names cp_function_chain->x_local_names
157 /* A list of objects which have constructors or destructors
158 which reside in the global scope. The decl is stored in
159 the TREE_VALUE slot and the initializer is stored
160 in the TREE_PURPOSE slot. */
161 tree static_aggregates;
165 /* A node for the integer constants 2, and 3. */
167 tree integer_two_node, integer_three_node;
169 /* Used only for jumps to as-yet undefined labels, since jumps to
170 defined labels can have their validity checked immediately. */
172 struct GTY(()) named_label_use_entry {
173 struct named_label_use_entry *next;
174 /* The binding level to which this entry is *currently* attached.
175 This is initially the binding level in which the goto appeared,
176 but is modified as scopes are closed. */
177 struct cp_binding_level *binding_level;
178 /* The head of the names list that was current when the goto appeared,
179 or the inner scope popped. These are the decls that will *not* be
180 skipped when jumping to the label. */
182 /* The location of the goto, for error reporting. */
183 location_t o_goto_locus;
184 /* True if an OpenMP structured block scope has been closed since
185 the goto appeared. This means that the branch from the label will
186 illegally exit an OpenMP scope. */
190 /* A list of all LABEL_DECLs in the function that have names. Here so
191 we can clear out their names' definitions at the end of the
192 function, and so we can check the validity of jumps to these labels. */
194 struct GTY(()) named_label_entry {
195 /* The decl itself. */
198 /* The binding level to which the label is *currently* attached.
199 This is initially set to the binding level in which the label
200 is defined, but is modified as scopes are closed. */
201 struct cp_binding_level *binding_level;
202 /* The head of the names list that was current when the label was
203 defined, or the inner scope popped. These are the decls that will
204 be skipped when jumping to the label. */
206 /* A tree list of all decls from all binding levels that would be
207 crossed by a backward branch to the label. */
210 /* A list of uses of the label, before the label is defined. */
211 struct named_label_use_entry *uses;
213 /* The following bits are set after the label is defined, and are
214 updated as scopes are popped. They indicate that a backward jump
215 to the label will illegally enter a scope of the given flavor. */
221 #define named_labels cp_function_chain->x_named_labels
223 /* The number of function bodies which we are currently processing.
224 (Zero if we are at namespace scope, one inside the body of a
225 function, two inside the body of a function in a local class, etc.) */
228 /* To avoid unwanted recursion, finish_function defers all mark_used calls
229 encountered during its execution until it finishes. */
230 bool defer_mark_used_calls;
231 VEC(tree, gc) *deferred_mark_used_calls;
233 /* States indicating how grokdeclarator() should handle declspecs marked
234 with __attribute__((deprecated)). An object declared as
235 __attribute__((deprecated)) suppresses warnings of uses of other
237 enum deprecated_states deprecated_state = DEPRECATED_NORMAL;
240 /* A TREE_LIST of VAR_DECLs. The TREE_PURPOSE is a RECORD_TYPE or
241 UNION_TYPE; the TREE_VALUE is a VAR_DECL with that type. At the
242 time the VAR_DECL was declared, the type was incomplete. */
244 static GTY(()) tree incomplete_vars;
246 /* Returns the kind of template specialization we are currently
247 processing, given that it's declaration contained N_CLASS_SCOPES
248 explicit scope qualifications. */
251 current_tmpl_spec_kind (int n_class_scopes)
253 int n_template_parm_scopes = 0;
254 int seen_specialization_p = 0;
255 int innermost_specialization_p = 0;
256 struct cp_binding_level *b;
258 /* Scan through the template parameter scopes. */
259 for (b = current_binding_level;
260 b->kind == sk_template_parms;
263 /* If we see a specialization scope inside a parameter scope,
264 then something is wrong. That corresponds to a declaration
267 template <class T> template <> ...
269 which is always invalid since [temp.expl.spec] forbids the
270 specialization of a class member template if the enclosing
271 class templates are not explicitly specialized as well. */
272 if (b->explicit_spec_p)
274 if (n_template_parm_scopes == 0)
275 innermost_specialization_p = 1;
277 seen_specialization_p = 1;
279 else if (seen_specialization_p == 1)
280 return tsk_invalid_member_spec;
282 ++n_template_parm_scopes;
285 /* Handle explicit instantiations. */
286 if (processing_explicit_instantiation)
288 if (n_template_parm_scopes != 0)
289 /* We've seen a template parameter list during an explicit
290 instantiation. For example:
292 template <class T> template void f(int);
294 This is erroneous. */
295 return tsk_invalid_expl_inst;
297 return tsk_expl_inst;
300 if (n_template_parm_scopes < n_class_scopes)
301 /* We've not seen enough template headers to match all the
302 specialized classes present. For example:
304 template <class T> void R<T>::S<T>::f(int);
306 This is invalid; there needs to be one set of template
307 parameters for each class. */
308 return tsk_insufficient_parms;
309 else if (n_template_parm_scopes == n_class_scopes)
310 /* We're processing a non-template declaration (even though it may
311 be a member of a template class.) For example:
313 template <class T> void S<T>::f(int);
315 The `class T' matches the `S<T>', leaving no template headers
316 corresponding to the `f'. */
318 else if (n_template_parm_scopes > n_class_scopes + 1)
319 /* We've got too many template headers. For example:
321 template <> template <class T> void f (T);
323 There need to be more enclosing classes. */
324 return tsk_excessive_parms;
326 /* This must be a template. It's of the form:
328 template <class T> template <class U> void S<T>::f(U);
330 This is a specialization if the innermost level was a
331 specialization; otherwise it's just a definition of the
333 return innermost_specialization_p ? tsk_expl_spec : tsk_template;
336 /* Exit the current scope. */
344 /* When a label goes out of scope, check to see if that label was used
345 in a valid manner, and issue any appropriate warnings or errors. */
348 pop_label (tree label, tree old_value)
350 if (!processing_template_decl)
352 if (DECL_INITIAL (label) == NULL_TREE)
356 error ("label %q+D used but not defined", label);
357 location = input_location; /* FIXME want (input_filename, (line)0) */
358 /* Avoid crashing later. */
359 define_label (location, DECL_NAME (label));
362 warn_for_unused_label (label);
365 SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (label), old_value);
368 /* At the end of a function, all labels declared within the function
369 go out of scope. BLOCK is the top-level block for the
373 pop_labels_1 (void **slot, void *data)
375 struct named_label_entry *ent = (struct named_label_entry *) *slot;
376 tree block = (tree) data;
378 pop_label (ent->label_decl, NULL_TREE);
380 /* Put the labels into the "variables" of the top-level block,
381 so debugger can see them. */
382 TREE_CHAIN (ent->label_decl) = BLOCK_VARS (block);
383 BLOCK_VARS (block) = ent->label_decl;
385 htab_clear_slot (named_labels, slot);
391 pop_labels (tree block)
395 htab_traverse (named_labels, pop_labels_1, block);
400 /* At the end of a block with local labels, restore the outer definition. */
403 pop_local_label (tree label, tree old_value)
405 struct named_label_entry dummy;
408 pop_label (label, old_value);
410 dummy.label_decl = label;
411 slot = htab_find_slot (named_labels, &dummy, NO_INSERT);
412 htab_clear_slot (named_labels, slot);
415 /* The following two routines are used to interface to Objective-C++.
416 The binding level is purposely treated as an opaque type. */
419 objc_get_current_scope (void)
421 return current_binding_level;
424 /* The following routine is used by the NeXT-style SJLJ exceptions;
425 variables get marked 'volatile' so as to not be clobbered by
426 _setjmp()/_longjmp() calls. All variables in the current scope,
427 as well as parent scopes up to (but not including) ENCLOSING_BLK
428 shall be thusly marked. */
431 objc_mark_locals_volatile (void *enclosing_blk)
433 struct cp_binding_level *scope;
435 for (scope = current_binding_level;
436 scope && scope != enclosing_blk;
437 scope = scope->level_chain)
441 for (decl = scope->names; decl; decl = TREE_CHAIN (decl))
442 objc_volatilize_decl (decl);
444 /* Do not climb up past the current function. */
445 if (scope->kind == sk_function_parms)
450 /* Update data for defined and undefined labels when leaving a scope. */
453 poplevel_named_label_1 (void **slot, void *data)
455 struct named_label_entry *ent = (struct named_label_entry *) *slot;
456 struct cp_binding_level *bl = (struct cp_binding_level *) data;
457 struct cp_binding_level *obl = bl->level_chain;
459 if (ent->binding_level == bl)
463 for (decl = ent->names_in_scope; decl; decl = TREE_CHAIN (decl))
464 if (decl_jump_unsafe (decl))
465 ent->bad_decls = tree_cons (NULL, decl, ent->bad_decls);
467 ent->binding_level = obl;
468 ent->names_in_scope = obl->names;
472 ent->in_try_scope = true;
475 ent->in_catch_scope = true;
478 ent->in_omp_scope = true;
486 struct named_label_use_entry *use;
488 for (use = ent->uses; use ; use = use->next)
489 if (use->binding_level == bl)
491 use->binding_level = obl;
492 use->names_in_scope = obl->names;
493 if (bl->kind == sk_omp)
494 use->in_omp_scope = true;
501 /* Saved errorcount to avoid -Wunused-but-set-{parameter,variable} warnings
502 when errors were reported, except for -Werror-unused-but-set-*. */
503 static int unused_but_set_errorcount;
505 /* Exit a binding level.
506 Pop the level off, and restore the state of the identifier-decl mappings
507 that were in effect when this level was entered.
509 If KEEP == 1, this level had explicit declarations, so
510 and create a "block" (a BLOCK node) for the level
511 to record its declarations and subblocks for symbol table output.
513 If FUNCTIONBODY is nonzero, this level is the body of a function,
514 so create a block as if KEEP were set and also clear out all
517 If REVERSE is nonzero, reverse the order of decls before putting
518 them into the BLOCK. */
521 poplevel (int keep, int reverse, int functionbody)
524 /* The chain of decls was accumulated in reverse order.
525 Put it into forward order, just for cleanliness. */
530 int leaving_for_scope;
533 timevar_push (TV_NAME_LOOKUP);
538 gcc_assert (current_binding_level->kind != sk_class);
540 if (current_binding_level->kind == sk_cleanup)
542 subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
544 gcc_assert (!VEC_length(cp_class_binding,
545 current_binding_level->class_shadowed));
547 /* We used to use KEEP == 2 to indicate that the new block should go
548 at the beginning of the list of blocks at this binding level,
549 rather than the end. This hack is no longer used. */
550 gcc_assert (keep == 0 || keep == 1);
552 if (current_binding_level->keep)
555 /* Any uses of undefined labels, and any defined labels, now operate
556 under constraints of next binding contour. */
557 if (cfun && !functionbody && named_labels)
558 htab_traverse (named_labels, poplevel_named_label_1,
559 current_binding_level);
561 /* Get the decls in the order they were written.
562 Usually current_binding_level->names is in reverse order.
563 But parameter decls were previously put in forward order. */
566 current_binding_level->names
567 = decls = nreverse (current_binding_level->names);
569 decls = current_binding_level->names;
571 /* If there were any declarations or structure tags in that level,
572 or if this level is a function body,
573 create a BLOCK to record them for the life of this function. */
575 if (keep == 1 || functionbody)
576 block = make_node (BLOCK);
577 if (block != NULL_TREE)
579 BLOCK_VARS (block) = decls;
580 BLOCK_SUBBLOCKS (block) = subblocks;
583 /* In each subblock, record that this is its superior. */
585 for (link = subblocks; link; link = BLOCK_CHAIN (link))
586 BLOCK_SUPERCONTEXT (link) = block;
588 /* We still support the old for-scope rules, whereby the variables
589 in a for-init statement were in scope after the for-statement
590 ended. We only use the new rules if flag_new_for_scope is
593 = current_binding_level->kind == sk_for && flag_new_for_scope == 1;
595 /* Before we remove the declarations first check for unused variables. */
596 if ((warn_unused_variable || warn_unused_but_set_variable)
597 && !processing_template_decl)
598 for (decl = getdecls (); decl; decl = TREE_CHAIN (decl))
599 if (TREE_CODE (decl) == VAR_DECL
600 && (! TREE_USED (decl) || !DECL_READ_P (decl))
601 && ! DECL_IN_SYSTEM_HEADER (decl)
602 && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl))
604 if (! TREE_USED (decl))
605 warning (OPT_Wunused_variable, "unused variable %q+D", decl);
606 else if (DECL_CONTEXT (decl) == current_function_decl
607 && TREE_TYPE (decl) != error_mark_node
608 && TREE_CODE (TREE_TYPE (decl)) != REFERENCE_TYPE
609 && errorcount == unused_but_set_errorcount
610 && (!CLASS_TYPE_P (TREE_TYPE (decl))
611 || !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (decl))))
613 warning (OPT_Wunused_but_set_variable,
614 "variable %q+D set but not used", decl);
615 unused_but_set_errorcount = errorcount;
619 /* Remove declarations for all the DECLs in this level. */
620 for (link = decls; link; link = TREE_CHAIN (link))
622 if (leaving_for_scope && TREE_CODE (link) == VAR_DECL
625 tree name = DECL_NAME (link);
629 ob = outer_binding (name,
630 IDENTIFIER_BINDING (name),
633 ns_binding = IDENTIFIER_NAMESPACE_VALUE (name);
635 ns_binding = NULL_TREE;
637 if (ob && ob->scope == current_binding_level->level_chain)
638 /* We have something like:
643 and we are leaving the `for' scope. There's no reason to
644 keep the binding of the inner `i' in this case. */
645 pop_binding (name, link);
646 else if ((ob && (TREE_CODE (ob->value) == TYPE_DECL))
647 || (ns_binding && TREE_CODE (ns_binding) == TYPE_DECL))
648 /* Here, we have something like:
656 We must pop the for-scope binding so we know what's a
657 type and what isn't. */
658 pop_binding (name, link);
661 /* Mark this VAR_DECL as dead so that we can tell we left it
662 there only for backward compatibility. */
663 DECL_DEAD_FOR_LOCAL (link) = 1;
665 /* Keep track of what should have happened when we
666 popped the binding. */
669 SET_DECL_SHADOWED_FOR_VAR (link, ob->value);
670 DECL_HAS_SHADOWED_FOR_VAR_P (link) = 1;
673 /* Add it to the list of dead variables in the next
674 outermost binding to that we can remove these when we
675 leave that binding. */
676 current_binding_level->level_chain->dead_vars_from_for
677 = tree_cons (NULL_TREE, link,
678 current_binding_level->level_chain->
681 /* Although we don't pop the cxx_binding, we do clear
682 its SCOPE since the scope is going away now. */
683 IDENTIFIER_BINDING (name)->scope
684 = current_binding_level->level_chain;
691 /* Remove the binding. */
694 if (TREE_CODE (decl) == TREE_LIST)
695 decl = TREE_VALUE (decl);
698 if (TREE_CODE (name) == OVERLOAD)
699 name = OVL_FUNCTION (name);
701 gcc_assert (DECL_P (name));
702 pop_binding (DECL_NAME (name), decl);
706 /* Remove declarations for any `for' variables from inner scopes
707 that we kept around. */
708 for (link = current_binding_level->dead_vars_from_for;
709 link; link = TREE_CHAIN (link))
710 pop_binding (DECL_NAME (TREE_VALUE (link)), TREE_VALUE (link));
712 /* Restore the IDENTIFIER_TYPE_VALUEs. */
713 for (link = current_binding_level->type_shadowed;
714 link; link = TREE_CHAIN (link))
715 SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link), TREE_VALUE (link));
717 /* Restore the IDENTIFIER_LABEL_VALUEs for local labels. */
718 for (link = current_binding_level->shadowed_labels;
720 link = TREE_CHAIN (link))
721 pop_local_label (TREE_VALUE (link), TREE_PURPOSE (link));
723 /* There may be OVERLOADs (wrapped in TREE_LISTs) on the BLOCK_VARs
724 list if a `using' declaration put them there. The debugging
725 back ends won't understand OVERLOAD, so we remove them here.
726 Because the BLOCK_VARS are (temporarily) shared with
727 CURRENT_BINDING_LEVEL->NAMES we must do this fixup after we have
728 popped all the bindings. */
733 for (d = &BLOCK_VARS (block); *d; )
735 if (TREE_CODE (*d) == TREE_LIST)
736 *d = TREE_CHAIN (*d);
738 d = &TREE_CHAIN (*d);
742 /* If the level being exited is the top level of a function,
743 check over all the labels. */
746 /* Since this is the top level block of a function, the vars are
747 the function's parameters. Don't leave them in the BLOCK
748 because they are found in the FUNCTION_DECL instead. */
749 BLOCK_VARS (block) = 0;
753 kind = current_binding_level->kind;
754 if (kind == sk_cleanup)
758 /* If this is a temporary binding created for a cleanup, then we'll
759 have pushed a statement list level. Pop that, create a new
760 BIND_EXPR for the block, and insert it into the stream. */
761 stmt = pop_stmt_list (current_binding_level->statement_list);
762 stmt = c_build_bind_expr (input_location, block, stmt);
769 /* The current function is being defined, so its DECL_INITIAL
770 should be error_mark_node. */
771 gcc_assert (DECL_INITIAL (current_function_decl) == error_mark_node);
772 DECL_INITIAL (current_function_decl) = block;
775 current_binding_level->blocks
776 = chainon (current_binding_level->blocks, block);
778 /* If we did not make a block for the level just exited,
779 any blocks made for inner levels
780 (since they cannot be recorded as subblocks in that level)
781 must be carried forward so they will later become subblocks
782 of something else. */
784 current_binding_level->blocks
785 = chainon (current_binding_level->blocks, subblocks);
787 /* Each and every BLOCK node created here in `poplevel' is important
788 (e.g. for proper debugging information) so if we created one
789 earlier, mark it as "used". */
791 TREE_USED (block) = 1;
793 /* All temporary bindings created for cleanups are popped silently. */
794 if (kind == sk_cleanup)
797 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, block);
800 /* Walk all the namespaces contained NAMESPACE, including NAMESPACE
801 itself, calling F for each. The DATA is passed to F as well. */
804 walk_namespaces_r (tree name_space, walk_namespaces_fn f, void* data)
807 tree current = NAMESPACE_LEVEL (name_space)->namespaces;
809 result |= (*f) (name_space, data);
811 for (; current; current = TREE_CHAIN (current))
812 result |= walk_namespaces_r (current, f, data);
817 /* Walk all the namespaces, calling F for each. The DATA is passed to
821 walk_namespaces (walk_namespaces_fn f, void* data)
823 return walk_namespaces_r (global_namespace, f, data);
826 /* Call wrapup_globals_declarations for the globals in NAMESPACE. If
827 DATA is non-NULL, this is the last time we will call
828 wrapup_global_declarations for this NAMESPACE. */
831 wrapup_globals_for_namespace (tree name_space, void* data)
833 struct cp_binding_level *level = NAMESPACE_LEVEL (name_space);
834 VEC(tree,gc) *statics = level->static_decls;
835 tree *vec = VEC_address (tree, statics);
836 int len = VEC_length (tree, statics);
837 int last_time = (data != 0);
841 check_global_declarations (vec, len);
842 emit_debug_global_declarations (vec, len);
846 /* Write out any globals that need to be output. */
847 return wrapup_global_declarations (vec, len);
851 /* In C++, you don't have to write `struct S' to refer to `S'; you
852 can just use `S'. We accomplish this by creating a TYPE_DECL as
853 if the user had written `typedef struct S S'. Create and return
854 the TYPE_DECL for TYPE. */
857 create_implicit_typedef (tree name, tree type)
861 decl = build_decl (input_location, TYPE_DECL, name, type);
862 DECL_ARTIFICIAL (decl) = 1;
863 /* There are other implicit type declarations, like the one *within*
864 a class that allows you to write `S::S'. We must distinguish
866 SET_DECL_IMPLICIT_TYPEDEF_P (decl);
867 TYPE_NAME (type) = decl;
868 TYPE_STUB_DECL (type) = decl;
873 /* Remember a local name for name-mangling purposes. */
876 push_local_name (tree decl)
881 timevar_push (TV_NAME_LOOKUP);
883 name = DECL_NAME (decl);
885 nelts = VEC_length (tree, local_names);
886 for (i = 0; i < nelts; i++)
888 t = VEC_index (tree, local_names, i);
889 if (DECL_NAME (t) == name)
891 if (!DECL_LANG_SPECIFIC (decl))
892 retrofit_lang_decl (decl);
893 DECL_LANG_SPECIFIC (decl)->u.base.u2sel = 1;
894 if (DECL_LANG_SPECIFIC (t))
895 DECL_DISCRIMINATOR (decl) = DECL_DISCRIMINATOR (t) + 1;
897 DECL_DISCRIMINATOR (decl) = 1;
899 VEC_replace (tree, local_names, i, decl);
900 timevar_pop (TV_NAME_LOOKUP);
905 VEC_safe_push (tree, gc, local_names, decl);
906 timevar_pop (TV_NAME_LOOKUP);
909 /* Subroutine of duplicate_decls: return truthvalue of whether
910 or not types of these decls match.
912 For C++, we must compare the parameter list so that `int' can match
913 `int&' in a parameter position, but `int&' is not confused with
917 decls_match (tree newdecl, tree olddecl)
921 if (newdecl == olddecl)
924 if (TREE_CODE (newdecl) != TREE_CODE (olddecl))
925 /* If the two DECLs are not even the same kind of thing, we're not
926 interested in their types. */
929 if (TREE_CODE (newdecl) == FUNCTION_DECL)
931 tree f1 = TREE_TYPE (newdecl);
932 tree f2 = TREE_TYPE (olddecl);
933 tree p1 = TYPE_ARG_TYPES (f1);
934 tree p2 = TYPE_ARG_TYPES (f2);
936 /* Specializations of different templates are different functions
937 even if they have the same type. */
938 tree t1 = (DECL_USE_TEMPLATE (newdecl)
939 ? DECL_TI_TEMPLATE (newdecl)
941 tree t2 = (DECL_USE_TEMPLATE (olddecl)
942 ? DECL_TI_TEMPLATE (olddecl)
947 if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
948 && ! (DECL_EXTERN_C_P (newdecl)
949 && DECL_EXTERN_C_P (olddecl)))
952 #ifdef NO_IMPLICIT_EXTERN_C
953 /* A new declaration doesn't match a built-in one unless it
954 is also extern "C". */
955 if (DECL_IS_BUILTIN (olddecl)
956 && DECL_EXTERN_C_P (olddecl) && !DECL_EXTERN_C_P (newdecl))
960 if (TREE_CODE (f1) != TREE_CODE (f2))
963 if (same_type_p (TREE_TYPE (f1), TREE_TYPE (f2)))
965 if (p2 == NULL_TREE && DECL_EXTERN_C_P (olddecl)
966 && (DECL_BUILT_IN (olddecl)
967 #ifndef NO_IMPLICIT_EXTERN_C
968 || (DECL_IN_SYSTEM_HEADER (newdecl) && !DECL_CLASS_SCOPE_P (newdecl))
969 || (DECL_IN_SYSTEM_HEADER (olddecl) && !DECL_CLASS_SCOPE_P (olddecl))
973 types_match = self_promoting_args_p (p1);
974 if (p1 == void_list_node)
975 TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
977 #ifndef NO_IMPLICIT_EXTERN_C
978 else if (p1 == NULL_TREE
979 && (DECL_EXTERN_C_P (olddecl)
980 && DECL_IN_SYSTEM_HEADER (olddecl)
981 && !DECL_CLASS_SCOPE_P (olddecl))
982 && (DECL_EXTERN_C_P (newdecl)
983 && DECL_IN_SYSTEM_HEADER (newdecl)
984 && !DECL_CLASS_SCOPE_P (newdecl)))
986 types_match = self_promoting_args_p (p2);
987 TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
991 types_match = compparms (p1, p2);
996 else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
998 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl))
999 != TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)))
1002 if (!comp_template_parms (DECL_TEMPLATE_PARMS (newdecl),
1003 DECL_TEMPLATE_PARMS (olddecl)))
1006 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL)
1007 types_match = same_type_p (TREE_TYPE (DECL_TEMPLATE_RESULT (olddecl)),
1008 TREE_TYPE (DECL_TEMPLATE_RESULT (newdecl)));
1010 types_match = decls_match (DECL_TEMPLATE_RESULT (olddecl),
1011 DECL_TEMPLATE_RESULT (newdecl));
1015 /* Need to check scope for variable declaration (VAR_DECL).
1016 For typedef (TYPE_DECL), scope is ignored. */
1017 if (TREE_CODE (newdecl) == VAR_DECL
1018 && CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
1020 Two declarations for an object with C language linkage
1021 with the same name (ignoring the namespace that qualify
1022 it) that appear in different namespace scopes refer to
1024 && !(DECL_EXTERN_C_P (olddecl) && DECL_EXTERN_C_P (newdecl)))
1027 if (TREE_TYPE (newdecl) == error_mark_node)
1028 types_match = TREE_TYPE (olddecl) == error_mark_node;
1029 else if (TREE_TYPE (olddecl) == NULL_TREE)
1030 types_match = TREE_TYPE (newdecl) == NULL_TREE;
1031 else if (TREE_TYPE (newdecl) == NULL_TREE)
1034 types_match = comptypes (TREE_TYPE (newdecl),
1035 TREE_TYPE (olddecl),
1036 COMPARE_REDECLARATION);
1042 /* If NEWDECL is `static' and an `extern' was seen previously,
1043 warn about it. OLDDECL is the previous declaration.
1045 Note that this does not apply to the C++ case of declaring
1046 a variable `extern const' and then later `const'.
1048 Don't complain about built-in functions, since they are beyond
1049 the user's control. */
1052 warn_extern_redeclared_static (tree newdecl, tree olddecl)
1054 if (TREE_CODE (newdecl) == TYPE_DECL
1055 || TREE_CODE (newdecl) == TEMPLATE_DECL
1056 || TREE_CODE (newdecl) == CONST_DECL
1057 || TREE_CODE (newdecl) == NAMESPACE_DECL)
1060 /* Don't get confused by static member functions; that's a different
1062 if (TREE_CODE (newdecl) == FUNCTION_DECL
1063 && DECL_STATIC_FUNCTION_P (newdecl))
1066 /* If the old declaration was `static', or the new one isn't, then
1067 then everything is OK. */
1068 if (DECL_THIS_STATIC (olddecl) || !DECL_THIS_STATIC (newdecl))
1071 /* It's OK to declare a builtin function as `static'. */
1072 if (TREE_CODE (olddecl) == FUNCTION_DECL
1073 && DECL_ARTIFICIAL (olddecl))
1076 permerror (input_location, "%qD was declared %<extern%> and later %<static%>", newdecl);
1077 permerror (input_location, "previous declaration of %q+D", olddecl);
1080 /* NEW_DECL is a redeclaration of OLD_DECL; both are functions or
1081 function templates. If their exception specifications do not
1082 match, issue a diagnostic. */
1085 check_redeclaration_exception_specification (tree new_decl,
1090 tree new_exceptions;
1091 tree old_exceptions;
1093 new_type = TREE_TYPE (new_decl);
1094 new_exceptions = TYPE_RAISES_EXCEPTIONS (new_type);
1095 old_type = TREE_TYPE (old_decl);
1096 old_exceptions = TYPE_RAISES_EXCEPTIONS (old_type);
1100 If any declaration of a function has an exception-specification,
1101 all declarations, including the definition and an explicit
1102 specialization, of that function shall have an
1103 exception-specification with the same set of type-ids. */
1104 if ((pedantic || ! DECL_IN_SYSTEM_HEADER (old_decl))
1105 && ! DECL_IS_BUILTIN (old_decl)
1107 && !comp_except_specs (new_exceptions, old_exceptions,
1110 error ("declaration of %qF throws different exceptions", new_decl);
1111 error ("from previous declaration %q+F", old_decl);
1115 #define GNU_INLINE_P(fn) (DECL_DECLARED_INLINE_P (fn) \
1116 && lookup_attribute ("gnu_inline", \
1117 DECL_ATTRIBUTES (fn)))
1119 /* If NEWDECL is a redeclaration of OLDDECL, merge the declarations.
1120 If the redeclaration is invalid, a diagnostic is issued, and the
1121 error_mark_node is returned. Otherwise, OLDDECL is returned.
1123 If NEWDECL is not a redeclaration of OLDDECL, NULL_TREE is
1126 NEWDECL_IS_FRIEND is true if NEWDECL was declared as a friend. */
1129 duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend)
1131 unsigned olddecl_uid = DECL_UID (olddecl);
1132 int olddecl_friend = 0, types_match = 0, hidden_friend = 0;
1133 int new_defines_function = 0;
1134 tree new_template_info;
1136 if (newdecl == olddecl)
1139 types_match = decls_match (newdecl, olddecl);
1141 /* If either the type of the new decl or the type of the old decl is an
1142 error_mark_node, then that implies that we have already issued an
1143 error (earlier) for some bogus type specification, and in that case,
1144 it is rather pointless to harass the user with yet more error message
1145 about the same declaration, so just pretend the types match here. */
1146 if (TREE_TYPE (newdecl) == error_mark_node
1147 || TREE_TYPE (olddecl) == error_mark_node)
1148 return error_mark_node;
1150 if (DECL_P (olddecl)
1151 && TREE_CODE (newdecl) == FUNCTION_DECL
1152 && TREE_CODE (olddecl) == FUNCTION_DECL
1153 && (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl)))
1155 if (DECL_DECLARED_INLINE_P (newdecl)
1156 && DECL_UNINLINABLE (newdecl)
1157 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl)))
1158 /* Already warned elsewhere. */;
1159 else if (DECL_DECLARED_INLINE_P (olddecl)
1160 && DECL_UNINLINABLE (olddecl)
1161 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl)))
1162 /* Already warned. */;
1163 else if (DECL_DECLARED_INLINE_P (newdecl)
1164 && DECL_UNINLINABLE (olddecl)
1165 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl)))
1167 warning (OPT_Wattributes, "function %q+D redeclared as inline",
1169 warning (OPT_Wattributes, "previous declaration of %q+D "
1170 "with attribute noinline", olddecl);
1172 else if (DECL_DECLARED_INLINE_P (olddecl)
1173 && DECL_UNINLINABLE (newdecl)
1174 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl)))
1176 warning (OPT_Wattributes, "function %q+D redeclared with "
1177 "attribute noinline", newdecl);
1178 warning (OPT_Wattributes, "previous declaration of %q+D was inline",
1183 /* Check for redeclaration and other discrepancies. */
1184 if (TREE_CODE (olddecl) == FUNCTION_DECL
1185 && DECL_ARTIFICIAL (olddecl))
1187 gcc_assert (!DECL_HIDDEN_FRIEND_P (olddecl));
1188 if (TREE_CODE (newdecl) != FUNCTION_DECL)
1190 /* Avoid warnings redeclaring built-ins which have not been
1191 explicitly declared. */
1192 if (DECL_ANTICIPATED (olddecl))
1195 /* If you declare a built-in or predefined function name as static,
1196 the old definition is overridden, but optionally warn this was a
1197 bad choice of name. */
1198 if (! TREE_PUBLIC (newdecl))
1200 warning (OPT_Wshadow,
1201 DECL_BUILT_IN (olddecl)
1202 ? G_("shadowing built-in function %q#D")
1203 : G_("shadowing library function %q#D"), olddecl);
1204 /* Discard the old built-in function. */
1207 /* If the built-in is not ansi, then programs can override
1208 it even globally without an error. */
1209 else if (! DECL_BUILT_IN (olddecl))
1210 warning (0, "library function %q#D redeclared as non-function %q#D",
1214 error ("declaration of %q#D", newdecl);
1215 error ("conflicts with built-in declaration %q#D",
1220 else if (!types_match)
1222 /* Avoid warnings redeclaring built-ins which have not been
1223 explicitly declared. */
1224 if (DECL_ANTICIPATED (olddecl))
1226 /* Deal with fileptr_type_node. FILE type is not known
1227 at the time we create the builtins. */
1230 for (t1 = TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
1231 t2 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
1233 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
1236 else if (TREE_VALUE (t2) == fileptr_type_node)
1238 tree t = TREE_VALUE (t1);
1240 if (TREE_CODE (t) == POINTER_TYPE
1241 && TYPE_NAME (TREE_TYPE (t))
1242 && DECL_NAME (TYPE_NAME (TREE_TYPE (t)))
1243 == get_identifier ("FILE")
1244 && compparms (TREE_CHAIN (t1), TREE_CHAIN (t2)))
1246 tree oldargs = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
1248 TYPE_ARG_TYPES (TREE_TYPE (olddecl))
1249 = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
1250 types_match = decls_match (newdecl, olddecl);
1252 return duplicate_decls (newdecl, olddecl,
1254 TYPE_ARG_TYPES (TREE_TYPE (olddecl)) = oldargs;
1257 else if (! same_type_p (TREE_VALUE (t1), TREE_VALUE (t2)))
1260 else if ((DECL_EXTERN_C_P (newdecl)
1261 && DECL_EXTERN_C_P (olddecl))
1262 || compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
1263 TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
1265 /* A near match; override the builtin. */
1267 if (TREE_PUBLIC (newdecl))
1269 warning (0, "new declaration %q#D", newdecl);
1270 warning (0, "ambiguates built-in declaration %q#D",
1274 warning (OPT_Wshadow,
1275 DECL_BUILT_IN (olddecl)
1276 ? G_("shadowing built-in function %q#D")
1277 : G_("shadowing library function %q#D"), olddecl);
1280 /* Discard the old built-in function. */
1283 /* Replace the old RTL to avoid problems with inlining. */
1284 COPY_DECL_RTL (newdecl, olddecl);
1286 /* Even if the types match, prefer the new declarations type for
1287 built-ins which have not been explicitly declared, for
1288 exception lists, etc... */
1289 else if (DECL_ANTICIPATED (olddecl))
1291 tree type = TREE_TYPE (newdecl);
1292 tree attribs = (*targetm.merge_type_attributes)
1293 (TREE_TYPE (olddecl), type);
1295 type = cp_build_type_attribute_variant (type, attribs);
1296 TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = type;
1299 /* If a function is explicitly declared "throw ()", propagate that to
1300 the corresponding builtin. */
1301 if (DECL_BUILT_IN_CLASS (olddecl) == BUILT_IN_NORMAL
1302 && DECL_ANTICIPATED (olddecl)
1303 && TREE_NOTHROW (newdecl)
1304 && !TREE_NOTHROW (olddecl)
1305 && built_in_decls [DECL_FUNCTION_CODE (olddecl)] != NULL_TREE
1306 && built_in_decls [DECL_FUNCTION_CODE (olddecl)] != olddecl
1308 TREE_NOTHROW (built_in_decls [DECL_FUNCTION_CODE (olddecl)]) = 1;
1310 /* Whether or not the builtin can throw exceptions has no
1311 bearing on this declarator. */
1312 TREE_NOTHROW (olddecl) = 0;
1314 if (DECL_THIS_STATIC (newdecl) && !DECL_THIS_STATIC (olddecl))
1316 /* If a builtin function is redeclared as `static', merge
1317 the declarations, but make the original one static. */
1318 DECL_THIS_STATIC (olddecl) = 1;
1319 TREE_PUBLIC (olddecl) = 0;
1321 /* Make the old declaration consistent with the new one so
1322 that all remnants of the builtin-ness of this function
1323 will be banished. */
1324 SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
1325 COPY_DECL_RTL (newdecl, olddecl);
1328 else if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
1330 /* C++ Standard, 3.3, clause 4:
1331 "[Note: a namespace name or a class template name must be unique
1332 in its declarative region (7.3.2, clause 14). ]" */
1333 if (TREE_CODE (olddecl) != NAMESPACE_DECL
1334 && TREE_CODE (newdecl) != NAMESPACE_DECL
1335 && (TREE_CODE (olddecl) != TEMPLATE_DECL
1336 || TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) != TYPE_DECL)
1337 && (TREE_CODE (newdecl) != TEMPLATE_DECL
1338 || TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) != TYPE_DECL))
1340 if ((TREE_CODE (olddecl) == TYPE_DECL && DECL_ARTIFICIAL (olddecl)
1341 && TREE_CODE (newdecl) != TYPE_DECL)
1342 || (TREE_CODE (newdecl) == TYPE_DECL && DECL_ARTIFICIAL (newdecl)
1343 && TREE_CODE (olddecl) != TYPE_DECL))
1345 /* We do nothing special here, because C++ does such nasty
1346 things with TYPE_DECLs. Instead, just let the TYPE_DECL
1347 get shadowed, and know that if we need to find a TYPE_DECL
1348 for a given name, we can look in the IDENTIFIER_TYPE_VALUE
1349 slot of the identifier. */
1353 if ((TREE_CODE (newdecl) == FUNCTION_DECL
1354 && DECL_FUNCTION_TEMPLATE_P (olddecl))
1355 || (TREE_CODE (olddecl) == FUNCTION_DECL
1356 && DECL_FUNCTION_TEMPLATE_P (newdecl)))
1360 error ("%q#D redeclared as different kind of symbol", newdecl);
1361 if (TREE_CODE (olddecl) == TREE_LIST)
1362 olddecl = TREE_VALUE (olddecl);
1363 error ("previous declaration of %q+#D", olddecl);
1365 return error_mark_node;
1367 else if (!types_match)
1369 if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl))
1370 /* These are certainly not duplicate declarations; they're
1371 from different scopes. */
1374 if (TREE_CODE (newdecl) == TEMPLATE_DECL)
1376 /* The name of a class template may not be declared to refer to
1377 any other template, class, function, object, namespace, value,
1378 or type in the same scope. */
1379 if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == TYPE_DECL
1380 || TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL)
1382 error ("declaration of template %q#D", newdecl);
1383 error ("conflicts with previous declaration %q+#D", olddecl);
1385 else if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == FUNCTION_DECL
1386 && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == FUNCTION_DECL
1387 && compparms (TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (olddecl))),
1388 TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (newdecl))))
1389 && comp_template_parms (DECL_TEMPLATE_PARMS (newdecl),
1390 DECL_TEMPLATE_PARMS (olddecl))
1391 /* Template functions can be disambiguated by
1393 && same_type_p (TREE_TYPE (TREE_TYPE (newdecl)),
1394 TREE_TYPE (TREE_TYPE (olddecl))))
1396 error ("new declaration %q#D", newdecl);
1397 error ("ambiguates old declaration %q+#D", olddecl);
1401 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1403 if (DECL_EXTERN_C_P (newdecl) && DECL_EXTERN_C_P (olddecl))
1405 error ("declaration of C function %q#D conflicts with",
1407 error ("previous declaration %q+#D here", olddecl);
1409 else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
1410 TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
1412 error ("new declaration %q#D", newdecl);
1413 error ("ambiguates old declaration %q+#D", olddecl);
1414 return error_mark_node;
1421 error ("conflicting declaration %q#D", newdecl);
1422 error ("%q+D has a previous declaration as %q#D", olddecl, olddecl);
1423 return error_mark_node;
1426 else if (TREE_CODE (newdecl) == FUNCTION_DECL
1427 && ((DECL_TEMPLATE_SPECIALIZATION (olddecl)
1428 && (!DECL_TEMPLATE_INFO (newdecl)
1429 || (DECL_TI_TEMPLATE (newdecl)
1430 != DECL_TI_TEMPLATE (olddecl))))
1431 || (DECL_TEMPLATE_SPECIALIZATION (newdecl)
1432 && (!DECL_TEMPLATE_INFO (olddecl)
1433 || (DECL_TI_TEMPLATE (olddecl)
1434 != DECL_TI_TEMPLATE (newdecl))))))
1435 /* It's OK to have a template specialization and a non-template
1436 with the same type, or to have specializations of two
1437 different templates with the same type. Note that if one is a
1438 specialization, and the other is an instantiation of the same
1439 template, that we do not exit at this point. That situation
1440 can occur if we instantiate a template class, and then
1441 specialize one of its methods. This situation is valid, but
1442 the declarations must be merged in the usual way. */
1444 else if (TREE_CODE (newdecl) == FUNCTION_DECL
1445 && ((DECL_TEMPLATE_INSTANTIATION (olddecl)
1446 && !DECL_USE_TEMPLATE (newdecl))
1447 || (DECL_TEMPLATE_INSTANTIATION (newdecl)
1448 && !DECL_USE_TEMPLATE (olddecl))))
1449 /* One of the declarations is a template instantiation, and the
1450 other is not a template at all. That's OK. */
1452 else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
1454 /* In [namespace.alias] we have:
1456 In a declarative region, a namespace-alias-definition can be
1457 used to redefine a namespace-alias declared in that declarative
1458 region to refer only to the namespace to which it already
1461 Therefore, if we encounter a second alias directive for the same
1462 alias, we can just ignore the second directive. */
1463 if (DECL_NAMESPACE_ALIAS (newdecl)
1464 && (DECL_NAMESPACE_ALIAS (newdecl)
1465 == DECL_NAMESPACE_ALIAS (olddecl)))
1467 /* [namespace.alias]
1469 A namespace-name or namespace-alias shall not be declared as
1470 the name of any other entity in the same declarative region.
1471 A namespace-name defined at global scope shall not be
1472 declared as the name of any other entity in any global scope
1474 error ("declaration of namespace %qD conflicts with", newdecl);
1475 error ("previous declaration of namespace %q+D here", olddecl);
1476 return error_mark_node;
1480 const char *errmsg = redeclaration_error_message (newdecl, olddecl);
1483 error_at (DECL_SOURCE_LOCATION (newdecl), errmsg, newdecl);
1484 if (DECL_NAME (olddecl) != NULL_TREE)
1485 error ((DECL_INITIAL (olddecl) && namespace_bindings_p ())
1486 ? "%q+#D previously defined here"
1487 : "%q+#D previously declared here", olddecl);
1488 return error_mark_node;
1490 else if (TREE_CODE (olddecl) == FUNCTION_DECL
1491 && DECL_INITIAL (olddecl) != NULL_TREE
1492 && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) == NULL_TREE
1493 && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != NULL_TREE)
1495 /* Prototype decl follows defn w/o prototype. */
1496 warning_at (input_location, 0, "prototype for %q+#D", newdecl);
1497 warning_at (DECL_SOURCE_LOCATION (olddecl), 0,
1498 "follows non-prototype definition here");
1500 else if ((TREE_CODE (olddecl) == FUNCTION_DECL
1501 || TREE_CODE (olddecl) == VAR_DECL)
1502 && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))
1505 If two declarations of the same function or object
1506 specify different linkage-specifications ..., the program
1507 is ill-formed.... Except for functions with C++ linkage,
1508 a function declaration without a linkage specification
1509 shall not precede the first linkage specification for
1510 that function. A function can be declared without a
1511 linkage specification after an explicit linkage
1512 specification has been seen; the linkage explicitly
1513 specified in the earlier declaration is not affected by
1514 such a function declaration.
1516 DR 563 raises the question why the restrictions on
1517 functions should not also apply to objects. Older
1518 versions of G++ silently ignore the linkage-specification
1526 which is clearly wrong. Therefore, we now treat objects
1528 if (current_lang_depth () == 0)
1530 /* There is no explicit linkage-specification, so we use
1531 the linkage from the previous declaration. */
1532 if (!DECL_LANG_SPECIFIC (newdecl))
1533 retrofit_lang_decl (newdecl);
1534 SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
1538 error ("previous declaration of %q+#D with %qL linkage",
1539 olddecl, DECL_LANGUAGE (olddecl));
1540 error ("conflicts with new declaration with %qL linkage",
1541 DECL_LANGUAGE (newdecl));
1545 if (DECL_LANG_SPECIFIC (olddecl) && DECL_USE_TEMPLATE (olddecl))
1547 else if (TREE_CODE (olddecl) == FUNCTION_DECL)
1549 tree t1 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
1550 tree t2 = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
1553 if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE)
1554 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2);
1556 for (; t1 && t1 != void_list_node;
1557 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++)
1558 if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
1560 if (1 == simple_cst_equal (TREE_PURPOSE (t1),
1563 permerror (input_location, "default argument given for parameter %d of %q#D",
1565 permerror (input_location, "after previous specification in %q+#D", olddecl);
1569 error ("default argument given for parameter %d of %q#D",
1571 error ("after previous specification in %q+#D",
1578 /* Do not merge an implicit typedef with an explicit one. In:
1582 typedef class A A __attribute__ ((foo));
1584 the attribute should apply only to the typedef. */
1585 if (TREE_CODE (olddecl) == TYPE_DECL
1586 && (DECL_IMPLICIT_TYPEDEF_P (olddecl)
1587 || DECL_IMPLICIT_TYPEDEF_P (newdecl)))
1590 /* If new decl is `static' and an `extern' was seen previously,
1592 warn_extern_redeclared_static (newdecl, olddecl);
1594 /* We have committed to returning 1 at this point. */
1595 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1597 /* Now that functions must hold information normally held
1598 by field decls, there is extra work to do so that
1599 declaration information does not get destroyed during
1601 if (DECL_VINDEX (olddecl))
1602 DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
1603 if (DECL_CONTEXT (olddecl))
1604 DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
1605 DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl);
1606 DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
1607 DECL_PURE_VIRTUAL_P (newdecl) |= DECL_PURE_VIRTUAL_P (olddecl);
1608 DECL_VIRTUAL_P (newdecl) |= DECL_VIRTUAL_P (olddecl);
1609 DECL_INVALID_OVERRIDER_P (newdecl) |= DECL_INVALID_OVERRIDER_P (olddecl);
1610 DECL_THIS_STATIC (newdecl) |= DECL_THIS_STATIC (olddecl);
1611 if (DECL_OVERLOADED_OPERATOR_P (olddecl) != ERROR_MARK)
1612 SET_OVERLOADED_OPERATOR_CODE
1613 (newdecl, DECL_OVERLOADED_OPERATOR_P (olddecl));
1614 new_defines_function = DECL_INITIAL (newdecl) != NULL_TREE;
1616 /* Optionally warn about more than one declaration for the same
1617 name, but don't warn about a function declaration followed by a
1619 if (warn_redundant_decls && ! DECL_ARTIFICIAL (olddecl)
1620 && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)
1621 /* Don't warn about extern decl followed by definition. */
1622 && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl))
1623 /* Don't warn about friends, let add_friend take care of it. */
1624 && ! (newdecl_is_friend || DECL_FRIEND_P (olddecl)))
1626 warning (OPT_Wredundant_decls, "redundant redeclaration of %qD in same scope", newdecl);
1627 warning (OPT_Wredundant_decls, "previous declaration of %q+D", olddecl);
1630 if (DECL_DELETED_FN (newdecl))
1632 error ("deleted definition of %qD", newdecl);
1633 error ("after previous declaration %q+D", olddecl);
1637 /* Deal with C++: must preserve virtual function table size. */
1638 if (TREE_CODE (olddecl) == TYPE_DECL)
1640 tree newtype = TREE_TYPE (newdecl);
1641 tree oldtype = TREE_TYPE (olddecl);
1643 if (newtype != error_mark_node && oldtype != error_mark_node
1644 && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype))
1645 CLASSTYPE_FRIEND_CLASSES (newtype)
1646 = CLASSTYPE_FRIEND_CLASSES (oldtype);
1648 DECL_ORIGINAL_TYPE (newdecl) = DECL_ORIGINAL_TYPE (olddecl);
1651 /* Copy all the DECL_... slots specified in the new decl
1652 except for any that we copy here from the old type. */
1653 DECL_ATTRIBUTES (newdecl)
1654 = (*targetm.merge_decl_attributes) (olddecl, newdecl);
1656 if (TREE_CODE (newdecl) == TEMPLATE_DECL)
1660 old_result = DECL_TEMPLATE_RESULT (olddecl);
1661 new_result = DECL_TEMPLATE_RESULT (newdecl);
1662 TREE_TYPE (olddecl) = TREE_TYPE (old_result);
1663 DECL_TEMPLATE_SPECIALIZATIONS (olddecl)
1664 = chainon (DECL_TEMPLATE_SPECIALIZATIONS (olddecl),
1665 DECL_TEMPLATE_SPECIALIZATIONS (newdecl));
1667 DECL_ATTRIBUTES (old_result)
1668 = (*targetm.merge_decl_attributes) (old_result, new_result);
1670 if (DECL_FUNCTION_TEMPLATE_P (newdecl))
1672 if (GNU_INLINE_P (old_result) != GNU_INLINE_P (new_result)
1673 && DECL_INITIAL (new_result))
1675 if (DECL_INITIAL (old_result))
1676 DECL_UNINLINABLE (old_result) = 1;
1678 DECL_UNINLINABLE (old_result) = DECL_UNINLINABLE (new_result);
1679 DECL_EXTERNAL (old_result) = DECL_EXTERNAL (new_result);
1680 DECL_NOT_REALLY_EXTERN (old_result)
1681 = DECL_NOT_REALLY_EXTERN (new_result);
1682 DECL_INTERFACE_KNOWN (old_result)
1683 = DECL_INTERFACE_KNOWN (new_result);
1684 DECL_DECLARED_INLINE_P (old_result)
1685 = DECL_DECLARED_INLINE_P (new_result);
1686 DECL_DISREGARD_INLINE_LIMITS (old_result)
1687 |= DECL_DISREGARD_INLINE_LIMITS (new_result);
1692 DECL_DECLARED_INLINE_P (old_result)
1693 |= DECL_DECLARED_INLINE_P (new_result);
1694 DECL_DISREGARD_INLINE_LIMITS (old_result)
1695 |= DECL_DISREGARD_INLINE_LIMITS (new_result);
1696 check_redeclaration_exception_specification (newdecl, olddecl);
1700 /* If the new declaration is a definition, update the file and
1701 line information on the declaration, and also make
1702 the old declaration the same definition. */
1703 if (DECL_INITIAL (new_result) != NULL_TREE)
1705 DECL_SOURCE_LOCATION (olddecl)
1706 = DECL_SOURCE_LOCATION (old_result)
1707 = DECL_SOURCE_LOCATION (newdecl);
1708 DECL_INITIAL (old_result) = DECL_INITIAL (new_result);
1709 if (DECL_FUNCTION_TEMPLATE_P (newdecl))
1712 DECL_ARGUMENTS (old_result)
1713 = DECL_ARGUMENTS (new_result);
1714 for (parm = DECL_ARGUMENTS (old_result); parm;
1715 parm = TREE_CHAIN (parm))
1716 DECL_CONTEXT (parm) = old_result;
1725 /* Automatically handles default parameters. */
1726 tree oldtype = TREE_TYPE (olddecl);
1729 /* Merge the data types specified in the two decls. */
1730 newtype = merge_types (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
1732 /* If merge_types produces a non-typedef type, just use the old type. */
1733 if (TREE_CODE (newdecl) == TYPE_DECL
1734 && newtype == DECL_ORIGINAL_TYPE (newdecl))
1737 if (TREE_CODE (newdecl) == VAR_DECL)
1739 DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
1740 DECL_INITIALIZED_P (newdecl) |= DECL_INITIALIZED_P (olddecl);
1741 DECL_NONTRIVIALLY_INITIALIZED_P (newdecl)
1742 |= DECL_NONTRIVIALLY_INITIALIZED_P (olddecl);
1743 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (newdecl)
1744 |= DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (olddecl);
1746 /* Merge the threadprivate attribute from OLDDECL into NEWDECL. */
1747 if (DECL_LANG_SPECIFIC (olddecl)
1748 && CP_DECL_THREADPRIVATE_P (olddecl))
1750 /* Allocate a LANG_SPECIFIC structure for NEWDECL, if needed. */
1751 if (!DECL_LANG_SPECIFIC (newdecl))
1752 retrofit_lang_decl (newdecl);
1754 DECL_TLS_MODEL (newdecl) = DECL_TLS_MODEL (olddecl);
1755 CP_DECL_THREADPRIVATE_P (newdecl) = 1;
1759 /* Do this after calling `merge_types' so that default
1760 parameters don't confuse us. */
1761 else if (TREE_CODE (newdecl) == FUNCTION_DECL)
1762 check_redeclaration_exception_specification (newdecl, olddecl);
1763 TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
1765 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1766 check_default_args (newdecl);
1768 /* Lay the type out, unless already done. */
1769 if (! same_type_p (newtype, oldtype)
1770 && TREE_TYPE (newdecl) != error_mark_node
1771 && !(processing_template_decl && uses_template_parms (newdecl)))
1772 layout_type (TREE_TYPE (newdecl));
1774 if ((TREE_CODE (newdecl) == VAR_DECL
1775 || TREE_CODE (newdecl) == PARM_DECL
1776 || TREE_CODE (newdecl) == RESULT_DECL
1777 || TREE_CODE (newdecl) == FIELD_DECL
1778 || TREE_CODE (newdecl) == TYPE_DECL)
1779 && !(processing_template_decl && uses_template_parms (newdecl)))
1780 layout_decl (newdecl, 0);
1782 /* Merge the type qualifiers. */
1783 if (TREE_READONLY (newdecl))
1784 TREE_READONLY (olddecl) = 1;
1785 if (TREE_THIS_VOLATILE (newdecl))
1786 TREE_THIS_VOLATILE (olddecl) = 1;
1787 if (TREE_NOTHROW (newdecl))
1788 TREE_NOTHROW (olddecl) = 1;
1790 /* Merge deprecatedness. */
1791 if (TREE_DEPRECATED (newdecl))
1792 TREE_DEPRECATED (olddecl) = 1;
1794 /* Preserve function specific target and optimization options */
1795 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1797 if (DECL_FUNCTION_SPECIFIC_TARGET (olddecl)
1798 && !DECL_FUNCTION_SPECIFIC_TARGET (newdecl))
1799 DECL_FUNCTION_SPECIFIC_TARGET (newdecl)
1800 = DECL_FUNCTION_SPECIFIC_TARGET (olddecl);
1802 if (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl)
1803 && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl))
1804 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl)
1805 = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl);
1808 /* Merge the initialization information. */
1809 if (DECL_INITIAL (newdecl) == NULL_TREE
1810 && DECL_INITIAL (olddecl) != NULL_TREE)
1812 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
1813 DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
1814 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1816 DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
1817 DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl);
1821 /* Merge the section attribute.
1822 We want to issue an error if the sections conflict but that must be
1823 done later in decl_attributes since we are called before attributes
1825 if (DECL_SECTION_NAME (newdecl) == NULL_TREE)
1826 DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl);
1828 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1830 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
1831 |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
1832 DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
1833 TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
1834 TREE_NOTHROW (newdecl) |= TREE_NOTHROW (olddecl);
1835 DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
1836 DECL_IS_OPERATOR_NEW (newdecl) |= DECL_IS_OPERATOR_NEW (olddecl);
1837 DECL_PURE_P (newdecl) |= DECL_PURE_P (olddecl);
1838 TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
1839 DECL_LOOPING_CONST_OR_PURE_P (newdecl)
1840 |= DECL_LOOPING_CONST_OR_PURE_P (olddecl);
1841 /* Keep the old RTL. */
1842 COPY_DECL_RTL (olddecl, newdecl);
1844 else if (TREE_CODE (newdecl) == VAR_DECL
1845 && (DECL_SIZE (olddecl) || !DECL_SIZE (newdecl)))
1847 /* Keep the old RTL. We cannot keep the old RTL if the old
1848 declaration was for an incomplete object and the new
1849 declaration is not since many attributes of the RTL will
1851 COPY_DECL_RTL (olddecl, newdecl);
1854 /* If cannot merge, then use the new type and qualifiers,
1855 and don't preserve the old rtl. */
1858 /* Clean out any memory we had of the old declaration. */
1859 tree oldstatic = value_member (olddecl, static_aggregates);
1861 TREE_VALUE (oldstatic) = error_mark_node;
1863 TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
1864 TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
1865 TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
1866 TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
1869 /* Merge the storage class information. */
1870 merge_weak (newdecl, olddecl);
1872 if (DECL_ONE_ONLY (olddecl))
1873 DECL_COMDAT_GROUP (newdecl) = DECL_COMDAT_GROUP (olddecl);
1875 DECL_DEFER_OUTPUT (newdecl) |= DECL_DEFER_OUTPUT (olddecl);
1876 TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
1877 TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl);
1878 if (! DECL_EXTERNAL (olddecl))
1879 DECL_EXTERNAL (newdecl) = 0;
1881 new_template_info = NULL_TREE;
1882 if (DECL_LANG_SPECIFIC (newdecl) && DECL_LANG_SPECIFIC (olddecl))
1884 bool new_redefines_gnu_inline = false;
1886 if (new_defines_function
1887 && ((DECL_INTERFACE_KNOWN (olddecl)
1888 && TREE_CODE (olddecl) == FUNCTION_DECL)
1889 || (TREE_CODE (olddecl) == TEMPLATE_DECL
1890 && (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl))
1891 == FUNCTION_DECL))))
1895 if (TREE_CODE (fn) == TEMPLATE_DECL)
1896 fn = DECL_TEMPLATE_RESULT (olddecl);
1898 new_redefines_gnu_inline = GNU_INLINE_P (fn) && DECL_INITIAL (fn);
1901 if (!new_redefines_gnu_inline)
1903 DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl);
1904 DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl);
1905 DECL_COMDAT (newdecl) |= DECL_COMDAT (olddecl);
1907 DECL_TEMPLATE_INSTANTIATED (newdecl)
1908 |= DECL_TEMPLATE_INSTANTIATED (olddecl);
1909 DECL_ODR_USED (newdecl) |= DECL_ODR_USED (olddecl);
1911 /* If the OLDDECL is an instantiation and/or specialization,
1912 then the NEWDECL must be too. But, it may not yet be marked
1913 as such if the caller has created NEWDECL, but has not yet
1914 figured out that it is a redeclaration. */
1915 if (!DECL_USE_TEMPLATE (newdecl))
1916 DECL_USE_TEMPLATE (newdecl) = DECL_USE_TEMPLATE (olddecl);
1918 /* Don't really know how much of the language-specific
1919 values we should copy from old to new. */
1920 DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
1921 DECL_REPO_AVAILABLE_P (newdecl) = DECL_REPO_AVAILABLE_P (olddecl);
1922 DECL_INITIALIZED_IN_CLASS_P (newdecl)
1923 |= DECL_INITIALIZED_IN_CLASS_P (olddecl);
1925 if (LANG_DECL_HAS_MIN (newdecl))
1927 DECL_LANG_SPECIFIC (newdecl)->u.min.u2 =
1928 DECL_LANG_SPECIFIC (olddecl)->u.min.u2;
1929 if (DECL_TEMPLATE_INFO (newdecl))
1930 new_template_info = DECL_TEMPLATE_INFO (newdecl);
1931 DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
1933 /* Only functions have these fields. */
1934 if (TREE_CODE (newdecl) == FUNCTION_DECL
1935 || DECL_FUNCTION_TEMPLATE_P (newdecl))
1937 DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl);
1938 olddecl_friend = DECL_FRIEND_P (olddecl);
1939 hidden_friend = (DECL_ANTICIPATED (olddecl)
1940 && DECL_HIDDEN_FRIEND_P (olddecl)
1941 && newdecl_is_friend);
1942 DECL_BEFRIENDING_CLASSES (newdecl)
1943 = chainon (DECL_BEFRIENDING_CLASSES (newdecl),
1944 DECL_BEFRIENDING_CLASSES (olddecl));
1945 /* DECL_THUNKS is only valid for virtual functions,
1946 otherwise it is a DECL_FRIEND_CONTEXT. */
1947 if (DECL_VIRTUAL_P (newdecl))
1948 DECL_THUNKS (newdecl) = DECL_THUNKS (olddecl);
1950 /* Only variables have this field. */
1951 else if (TREE_CODE (newdecl) == VAR_DECL
1952 && VAR_HAD_UNKNOWN_BOUND (olddecl))
1953 SET_VAR_HAD_UNKNOWN_BOUND (newdecl);
1956 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1960 /* Merge parameter attributes. */
1961 tree oldarg, newarg;
1962 for (oldarg = DECL_ARGUMENTS(olddecl),
1963 newarg = DECL_ARGUMENTS(newdecl);
1965 oldarg = TREE_CHAIN(oldarg), newarg = TREE_CHAIN(newarg)) {
1966 DECL_ATTRIBUTES (newarg)
1967 = (*targetm.merge_decl_attributes) (oldarg, newarg);
1968 DECL_ATTRIBUTES (oldarg) = DECL_ATTRIBUTES (newarg);
1971 if (DECL_TEMPLATE_INSTANTIATION (olddecl)
1972 && !DECL_TEMPLATE_INSTANTIATION (newdecl))
1974 /* If newdecl is not a specialization, then it is not a
1975 template-related function at all. And that means that we
1976 should have exited above, returning 0. */
1977 gcc_assert (DECL_TEMPLATE_SPECIALIZATION (newdecl));
1979 if (DECL_ODR_USED (olddecl))
1980 /* From [temp.expl.spec]:
1982 If a template, a member template or the member of a class
1983 template is explicitly specialized then that
1984 specialization shall be declared before the first use of
1985 that specialization that would cause an implicit
1986 instantiation to take place, in every translation unit in
1987 which such a use occurs. */
1988 error ("explicit specialization of %qD after first use",
1991 SET_DECL_TEMPLATE_SPECIALIZATION (olddecl);
1993 /* Don't propagate visibility from the template to the
1994 specialization here. We'll do that in determine_visibility if
1996 DECL_VISIBILITY_SPECIFIED (olddecl) = 0;
1998 /* [temp.expl.spec/14] We don't inline explicit specialization
1999 just because the primary template says so. */
2001 else if (new_defines_function && DECL_INITIAL (olddecl))
2003 /* Never inline re-defined extern inline functions.
2004 FIXME: this could be better handled by keeping both
2005 function as separate declarations. */
2006 DECL_UNINLINABLE (newdecl) = 1;
2010 if (DECL_PENDING_INLINE_INFO (newdecl) == 0)
2011 DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl);
2013 DECL_DECLARED_INLINE_P (newdecl) |= DECL_DECLARED_INLINE_P (olddecl);
2015 DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
2016 = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
2018 DECL_DISREGARD_INLINE_LIMITS (newdecl)
2019 = DECL_DISREGARD_INLINE_LIMITS (olddecl)
2020 = (DECL_DISREGARD_INLINE_LIMITS (newdecl)
2021 || DECL_DISREGARD_INLINE_LIMITS (olddecl));
2024 /* Preserve abstractness on cloned [cd]tors. */
2025 DECL_ABSTRACT (newdecl) = DECL_ABSTRACT (olddecl);
2027 /* Update newdecl's parms to point at olddecl. */
2028 for (parm = DECL_ARGUMENTS (newdecl); parm;
2029 parm = TREE_CHAIN (parm))
2030 DECL_CONTEXT (parm) = olddecl;
2034 SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
2035 COPY_DECL_ASSEMBLER_NAME (newdecl, olddecl);
2036 COPY_DECL_RTL (newdecl, olddecl);
2038 if (! types_match || new_defines_function)
2040 /* These need to be copied so that the names are available.
2041 Note that if the types do match, we'll preserve inline
2042 info and other bits, but if not, we won't. */
2043 DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
2044 DECL_RESULT (olddecl) = DECL_RESULT (newdecl);
2046 if (new_defines_function)
2047 /* If defining a function declared with other language
2048 linkage, use the previously declared language linkage. */
2049 SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
2050 else if (types_match)
2052 /* If redeclaring a builtin function, and not a definition,
2053 it stays built in. */
2054 if (DECL_BUILT_IN (olddecl))
2056 DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl);
2057 DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
2058 /* If we're keeping the built-in definition, keep the rtl,
2059 regardless of declaration matches. */
2060 COPY_DECL_RTL (olddecl, newdecl);
2063 DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
2064 /* Don't clear out the arguments if we're just redeclaring a
2066 if (DECL_ARGUMENTS (olddecl))
2067 DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
2070 else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
2071 NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl);
2073 /* Now preserve various other info from the definition. */
2074 TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
2075 TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
2076 DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
2077 COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
2079 /* Warn about conflicting visibility specifications. */
2080 if (DECL_VISIBILITY_SPECIFIED (olddecl)
2081 && DECL_VISIBILITY_SPECIFIED (newdecl)
2082 && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
2084 warning_at (input_location, OPT_Wattributes,
2085 "%q+D: visibility attribute ignored because it", newdecl);
2086 warning_at (DECL_SOURCE_LOCATION (olddecl), OPT_Wattributes,
2087 "conflicts with previous declaration here");
2089 /* Choose the declaration which specified visibility. */
2090 if (DECL_VISIBILITY_SPECIFIED (olddecl))
2092 DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
2093 DECL_VISIBILITY_SPECIFIED (newdecl) = 1;
2095 /* Init priority used to be merged from newdecl to olddecl by the memcpy,
2096 so keep this behavior. */
2097 if (TREE_CODE (newdecl) == VAR_DECL && DECL_HAS_INIT_PRIORITY_P (newdecl))
2099 SET_DECL_INIT_PRIORITY (olddecl, DECL_INIT_PRIORITY (newdecl));
2100 DECL_HAS_INIT_PRIORITY_P (olddecl) = 1;
2103 /* The DECL_LANG_SPECIFIC information in OLDDECL will be replaced
2104 with that from NEWDECL below. */
2105 if (DECL_LANG_SPECIFIC (olddecl))
2107 gcc_assert (DECL_LANG_SPECIFIC (olddecl)
2108 != DECL_LANG_SPECIFIC (newdecl));
2109 ggc_free (DECL_LANG_SPECIFIC (olddecl));
2112 /* Merge the USED information. */
2113 if (TREE_USED (olddecl))
2114 TREE_USED (newdecl) = 1;
2115 else if (TREE_USED (newdecl))
2116 TREE_USED (olddecl) = 1;
2117 if (TREE_CODE (newdecl) == VAR_DECL)
2119 if (DECL_READ_P (olddecl))
2120 DECL_READ_P (newdecl) = 1;
2121 else if (DECL_READ_P (newdecl))
2122 DECL_READ_P (olddecl) = 1;
2124 if (DECL_PRESERVE_P (olddecl))
2125 DECL_PRESERVE_P (newdecl) = 1;
2126 else if (DECL_PRESERVE_P (newdecl))
2127 DECL_PRESERVE_P (olddecl) = 1;
2129 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2133 function_size = sizeof (struct tree_decl_common);
2135 memcpy ((char *) olddecl + sizeof (struct tree_common),
2136 (char *) newdecl + sizeof (struct tree_common),
2137 function_size - sizeof (struct tree_common));
2139 memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
2140 (char *) newdecl + sizeof (struct tree_decl_common),
2141 sizeof (struct tree_function_decl) - sizeof (struct tree_decl_common));
2142 if (new_template_info)
2143 /* If newdecl is a template instantiation, it is possible that
2144 the following sequence of events has occurred:
2146 o A friend function was declared in a class template. The
2147 class template was instantiated.
2149 o The instantiation of the friend declaration was
2150 recorded on the instantiation list, and is newdecl.
2152 o Later, however, instantiate_class_template called pushdecl
2153 on the newdecl to perform name injection. But, pushdecl in
2154 turn called duplicate_decls when it discovered that another
2155 declaration of a global function with the same name already
2158 o Here, in duplicate_decls, we decided to clobber newdecl.
2160 If we're going to do that, we'd better make sure that
2161 olddecl, and not newdecl, is on the list of
2162 instantiations so that if we try to do the instantiation
2163 again we won't get the clobbered declaration. */
2164 reregister_specialization (newdecl,
2170 size_t size = tree_code_size (TREE_CODE (olddecl));
2171 memcpy ((char *) olddecl + sizeof (struct tree_common),
2172 (char *) newdecl + sizeof (struct tree_common),
2173 sizeof (struct tree_decl_common) - sizeof (struct tree_common));
2174 switch (TREE_CODE (olddecl))
2184 memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
2185 (char *) newdecl + sizeof (struct tree_decl_common),
2186 size - sizeof (struct tree_decl_common)
2187 + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
2191 memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
2192 (char *) newdecl + sizeof (struct tree_decl_common),
2193 sizeof (struct tree_decl_non_common) - sizeof (struct tree_decl_common)
2194 + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
2198 DECL_UID (olddecl) = olddecl_uid;
2200 DECL_FRIEND_P (olddecl) = 1;
2203 DECL_ANTICIPATED (olddecl) = 1;
2204 DECL_HIDDEN_FRIEND_P (olddecl) = 1;
2207 /* NEWDECL contains the merged attribute lists.
2208 Update OLDDECL to be the same. */
2209 DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
2211 /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
2212 so that encode_section_info has a chance to look at the new decl
2213 flags and attributes. */
2214 if (DECL_RTL_SET_P (olddecl)
2215 && (TREE_CODE (olddecl) == FUNCTION_DECL
2216 || (TREE_CODE (olddecl) == VAR_DECL
2217 && TREE_STATIC (olddecl))))
2218 make_decl_rtl (olddecl);
2220 /* The NEWDECL will no longer be needed. Because every out-of-class
2221 declaration of a member results in a call to duplicate_decls,
2222 freeing these nodes represents in a significant savings. */
2228 /* Return zero if the declaration NEWDECL is valid
2229 when the declaration OLDDECL (assumed to be for the same name)
2230 has already been seen.
2231 Otherwise return an error message format string with a %s
2232 where the identifier should go. */
2235 redeclaration_error_message (tree newdecl, tree olddecl)
2237 if (TREE_CODE (newdecl) == TYPE_DECL)
2239 /* Because C++ can put things into name space for free,
2240 constructs like "typedef struct foo { ... } foo"
2241 would look like an erroneous redeclaration. */
2242 if (same_type_p (TREE_TYPE (newdecl), TREE_TYPE (olddecl)))
2245 return G_("redefinition of %q#D");
2247 else if (TREE_CODE (newdecl) == FUNCTION_DECL)
2249 /* If this is a pure function, its olddecl will actually be
2250 the original initialization to `0' (which we force to call
2251 abort()). Don't complain about redefinition in this case. */
2252 if (DECL_LANG_SPECIFIC (olddecl) && DECL_PURE_VIRTUAL_P (olddecl)
2253 && DECL_INITIAL (olddecl) == NULL_TREE)
2256 /* If both functions come from different namespaces, this is not
2257 a redeclaration - this is a conflict with a used function. */
2258 if (DECL_NAMESPACE_SCOPE_P (olddecl)
2259 && DECL_CONTEXT (olddecl) != DECL_CONTEXT (newdecl)
2260 && ! decls_match (olddecl, newdecl))
2261 return G_("%qD conflicts with used function");
2263 /* We'll complain about linkage mismatches in
2264 warn_extern_redeclared_static. */
2266 /* Defining the same name twice is no good. */
2267 if (DECL_INITIAL (olddecl) != NULL_TREE
2268 && DECL_INITIAL (newdecl) != NULL_TREE)
2270 if (DECL_NAME (olddecl) == NULL_TREE)
2271 return G_("%q#D not declared in class");
2272 else if (!GNU_INLINE_P (olddecl)
2273 || GNU_INLINE_P (newdecl))
2274 return G_("redefinition of %q#D");
2277 if (DECL_DECLARED_INLINE_P (olddecl) && DECL_DECLARED_INLINE_P (newdecl))
2279 bool olda = GNU_INLINE_P (olddecl);
2280 bool newa = GNU_INLINE_P (newdecl);
2285 return G_("%q+D redeclared inline with "
2286 "%<gnu_inline%> attribute");
2288 return G_("%q+D redeclared inline without "
2289 "%<gnu_inline%> attribute");
2295 else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
2299 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL)
2301 if (COMPLETE_TYPE_P (TREE_TYPE (newdecl))
2302 && COMPLETE_TYPE_P (TREE_TYPE (olddecl)))
2303 return G_("redefinition of %q#D");
2307 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) != FUNCTION_DECL
2308 || (DECL_TEMPLATE_RESULT (newdecl)
2309 == DECL_TEMPLATE_RESULT (olddecl)))
2312 nt = DECL_TEMPLATE_RESULT (newdecl);
2313 if (DECL_TEMPLATE_INFO (nt))
2314 nt = DECL_TEMPLATE_RESULT (template_for_substitution (nt));
2315 ot = DECL_TEMPLATE_RESULT (olddecl);
2316 if (DECL_TEMPLATE_INFO (ot))
2317 ot = DECL_TEMPLATE_RESULT (template_for_substitution (ot));
2318 if (DECL_INITIAL (nt) && DECL_INITIAL (ot)
2319 && (!GNU_INLINE_P (ot) || GNU_INLINE_P (nt)))
2320 return G_("redefinition of %q#D");
2322 if (DECL_DECLARED_INLINE_P (ot) && DECL_DECLARED_INLINE_P (nt))
2324 bool olda = GNU_INLINE_P (ot);
2325 bool newa = GNU_INLINE_P (nt);
2330 return G_("%q+D redeclared inline with "
2331 "%<gnu_inline%> attribute");
2333 return G_("%q+D redeclared inline without "
2334 "%<gnu_inline%> attribute");
2338 /* Core issue #226 (C++0x):
2340 If a friend function template declaration specifies a
2341 default template-argument, that declaration shall be a
2342 definition and shall be the only declaration of the
2343 function template in the translation unit. */
2344 if ((cxx_dialect != cxx98)
2345 && TREE_CODE (ot) == FUNCTION_DECL && DECL_FRIEND_P (ot)
2346 && !check_default_tmpl_args (nt, DECL_TEMPLATE_PARMS (newdecl),
2347 /*is_primary=*/1, /*is_partial=*/0,
2348 /*is_friend_decl=*/2))
2349 return G_("redeclaration of friend %q#D "
2350 "may not have default template arguments");
2354 else if (TREE_CODE (newdecl) == VAR_DECL
2355 && DECL_THREAD_LOCAL_P (newdecl) != DECL_THREAD_LOCAL_P (olddecl)
2356 && (! DECL_LANG_SPECIFIC (olddecl)
2357 || ! CP_DECL_THREADPRIVATE_P (olddecl)
2358 || DECL_THREAD_LOCAL_P (newdecl)))
2360 /* Only variables can be thread-local, and all declarations must
2361 agree on this property. */
2362 if (DECL_THREAD_LOCAL_P (newdecl))
2363 return G_("thread-local declaration of %q#D follows "
2364 "non-thread-local declaration");
2366 return G_("non-thread-local declaration of %q#D follows "
2367 "thread-local declaration");
2369 else if (toplevel_bindings_p () || DECL_NAMESPACE_SCOPE_P (newdecl))
2371 /* The objects have been declared at namespace scope. If either
2372 is a member of an anonymous union, then this is an invalid
2373 redeclaration. For example:
2379 if ((TREE_CODE (newdecl) == VAR_DECL && DECL_ANON_UNION_VAR_P (newdecl))
2380 || (TREE_CODE (olddecl) == VAR_DECL && DECL_ANON_UNION_VAR_P (olddecl)))
2381 return G_("redeclaration of %q#D");
2382 /* If at least one declaration is a reference, there is no
2383 conflict. For example:
2389 if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
2391 /* Reject two definitions. */
2392 return G_("redefinition of %q#D");
2396 /* Objects declared with block scope: */
2397 /* Reject two definitions, and reject a definition
2398 together with an external reference. */
2399 if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
2400 return G_("redeclaration of %q#D");
2405 /* Hash and equality functions for the named_label table. */
2408 named_label_entry_hash (const void *data)
2410 const struct named_label_entry *ent = (const struct named_label_entry *) data;
2411 return DECL_UID (ent->label_decl);
2415 named_label_entry_eq (const void *a, const void *b)
2417 const struct named_label_entry *ent_a = (const struct named_label_entry *) a;
2418 const struct named_label_entry *ent_b = (const struct named_label_entry *) b;
2419 return ent_a->label_decl == ent_b->label_decl;
2422 /* Create a new label, named ID. */
2425 make_label_decl (tree id, int local_p)
2427 struct named_label_entry *ent;
2431 decl = build_decl (input_location, LABEL_DECL, id, void_type_node);
2433 DECL_CONTEXT (decl) = current_function_decl;
2434 DECL_MODE (decl) = VOIDmode;
2435 C_DECLARED_LABEL_FLAG (decl) = local_p;
2437 /* Say where one reference is to the label, for the sake of the
2438 error if it is not defined. */
2439 DECL_SOURCE_LOCATION (decl) = input_location;
2441 /* Record the fact that this identifier is bound to this label. */
2442 SET_IDENTIFIER_LABEL_VALUE (id, decl);
2444 /* Create the label htab for the function on demand. */
2446 named_labels = htab_create_ggc (13, named_label_entry_hash,
2447 named_label_entry_eq, NULL);
2449 /* Record this label on the list of labels used in this function.
2450 We do this before calling make_label_decl so that we get the
2451 IDENTIFIER_LABEL_VALUE before the new label is declared. */
2452 ent = GGC_CNEW (struct named_label_entry);
2453 ent->label_decl = decl;
2455 slot = htab_find_slot (named_labels, ent, INSERT);
2456 gcc_assert (*slot == NULL);
2462 /* Look for a label named ID in the current function. If one cannot
2463 be found, create one. (We keep track of used, but undefined,
2464 labels, and complain about them at the end of a function.) */
2467 lookup_label (tree id)
2471 timevar_push (TV_NAME_LOOKUP);
2472 /* You can't use labels at global scope. */
2473 if (current_function_decl == NULL_TREE)
2475 error ("label %qE referenced outside of any function", id);
2476 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
2479 /* See if we've already got this label. */
2480 decl = IDENTIFIER_LABEL_VALUE (id);
2481 if (decl != NULL_TREE && DECL_CONTEXT (decl) == current_function_decl)
2482 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
2484 decl = make_label_decl (id, /*local_p=*/0);
2485 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
2488 /* Declare a local label named ID. */
2491 declare_local_label (tree id)
2495 /* Add a new entry to the SHADOWED_LABELS list so that when we leave
2496 this scope we can restore the old value of IDENTIFIER_TYPE_VALUE. */
2497 shadow = tree_cons (IDENTIFIER_LABEL_VALUE (id), NULL_TREE,
2498 current_binding_level->shadowed_labels);
2499 current_binding_level->shadowed_labels = shadow;
2501 decl = make_label_decl (id, /*local_p=*/1);
2502 TREE_VALUE (shadow) = decl;
2507 /* Returns nonzero if it is ill-formed to jump past the declaration of
2508 DECL. Returns 2 if it's also a real problem. */
2511 decl_jump_unsafe (tree decl)
2513 /* [stmt.dcl]/3: A program that jumps from a point where a local variable
2514 with automatic storage duration is not in scope to a point where it is
2515 in scope is ill-formed unless the variable has scalar type, class type
2516 with a trivial default constructor and a trivial destructor, a
2517 cv-qualified version of one of these types, or an array of one of the
2518 preceding types and is declared without an initializer (8.5). */
2519 tree type = TREE_TYPE (decl);
2521 if (TREE_CODE (decl) != VAR_DECL || TREE_STATIC (decl)
2522 || type == error_mark_node)
2525 type = strip_array_types (type);
2527 if (type_has_nontrivial_default_init (TREE_TYPE (decl))
2528 || DECL_NONTRIVIALLY_INITIALIZED_P (decl))
2531 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (decl)))
2537 /* A subroutine of check_previous_goto_1 to identify a branch to the user. */
2540 identify_goto (tree decl, const location_t *locus)
2543 permerror (input_location, "jump to label %qD", decl);
2545 permerror (input_location, "jump to case label");
2547 permerror (*locus, " from here");
2550 /* Check that a single previously seen jump to a newly defined label
2551 is OK. DECL is the LABEL_DECL or 0; LEVEL is the binding_level for
2552 the jump context; NAMES are the names in scope in LEVEL at the jump
2553 context; LOCUS is the source position of the jump or 0. Returns
2554 true if all is well. */
2557 check_previous_goto_1 (tree decl, struct cp_binding_level* level, tree names,
2558 bool exited_omp, const location_t *locus)
2560 struct cp_binding_level *b;
2561 bool identified = false, saw_eh = false, saw_omp = false;
2565 identify_goto (decl, locus);
2566 error (" exits OpenMP structured block");
2567 identified = saw_omp = true;
2570 for (b = current_binding_level; b ; b = b->level_chain)
2572 tree new_decls, old_decls = (b == level ? names : NULL_TREE);
2574 for (new_decls = b->names; new_decls != old_decls;
2575 new_decls = TREE_CHAIN (new_decls))
2577 int problem = decl_jump_unsafe (new_decls);
2583 identify_goto (decl, locus);
2587 error (" crosses initialization of %q+#D", new_decls);
2589 permerror (input_location, " enters scope of %q+#D which has "
2590 "non-trivial destructor", new_decls);
2595 if ((b->kind == sk_try || b->kind == sk_catch) && !saw_eh)
2599 identify_goto (decl, locus);
2602 if (b->kind == sk_try)
2603 error (" enters try block");
2605 error (" enters catch block");
2608 if (b->kind == sk_omp && !saw_omp)
2612 identify_goto (decl, locus);
2615 error (" enters OpenMP structured block");
2624 check_previous_goto (tree decl, struct named_label_use_entry *use)
2626 check_previous_goto_1 (decl, use->binding_level,
2627 use->names_in_scope, use->in_omp_scope,
2628 &use->o_goto_locus);
2632 check_switch_goto (struct cp_binding_level* level)
2634 return check_previous_goto_1 (NULL_TREE, level, level->names, false, NULL);
2637 /* Check that a new jump to a label DECL is OK. Called by
2638 finish_goto_stmt. */
2641 check_goto (tree decl)
2643 struct named_label_entry *ent, dummy;
2644 bool saw_catch = false, identified = false;
2647 /* We can't know where a computed goto is jumping.
2648 So we assume that it's OK. */
2649 if (TREE_CODE (decl) != LABEL_DECL)
2652 /* We didn't record any information about this label when we created it,
2653 and there's not much point since it's trivial to analyze as a return. */
2654 if (decl == cdtor_label)
2657 dummy.label_decl = decl;
2658 ent = (struct named_label_entry *) htab_find (named_labels, &dummy);
2659 gcc_assert (ent != NULL);
2661 /* If the label hasn't been defined yet, defer checking. */
2662 if (! DECL_INITIAL (decl))
2664 struct named_label_use_entry *new_use;
2666 /* Don't bother creating another use if the last goto had the
2667 same data, and will therefore create the same set of errors. */
2669 && ent->uses->names_in_scope == current_binding_level->names)
2672 new_use = GGC_NEW (struct named_label_use_entry);
2673 new_use->binding_level = current_binding_level;
2674 new_use->names_in_scope = current_binding_level->names;
2675 new_use->o_goto_locus = input_location;
2676 new_use->in_omp_scope = false;
2678 new_use->next = ent->uses;
2679 ent->uses = new_use;
2683 if (ent->in_try_scope || ent->in_catch_scope
2684 || ent->in_omp_scope || ent->bad_decls)
2686 permerror (input_location, "jump to label %q+D", decl);
2687 permerror (input_location, " from here");
2691 for (bad = ent->bad_decls; bad; bad = TREE_CHAIN (bad))
2693 tree b = TREE_VALUE (bad);
2694 int u = decl_jump_unsafe (b);
2696 if (u > 1 && DECL_ARTIFICIAL (b))
2698 /* Can't skip init of __exception_info. */
2699 error_at (DECL_SOURCE_LOCATION (b), " enters catch block");
2703 error (" skips initialization of %q+#D", b);
2705 permerror (input_location, " enters scope of %q+#D which has "
2706 "non-trivial destructor", b);
2709 if (ent->in_try_scope)
2710 error (" enters try block");
2711 else if (ent->in_catch_scope && !saw_catch)
2712 error (" enters catch block");
2714 if (ent->in_omp_scope)
2715 error (" enters OpenMP structured block");
2716 else if (flag_openmp)
2718 struct cp_binding_level *b;
2719 for (b = current_binding_level; b ; b = b->level_chain)
2721 if (b == ent->binding_level)
2723 if (b->kind == sk_omp)
2727 permerror (input_location, "jump to label %q+D", decl);
2728 permerror (input_location, " from here");
2731 error (" exits OpenMP structured block");
2738 /* Check that a return is ok wrt OpenMP structured blocks.
2739 Called by finish_return_stmt. Returns true if all is well. */
2742 check_omp_return (void)
2744 struct cp_binding_level *b;
2745 for (b = current_binding_level; b ; b = b->level_chain)
2746 if (b->kind == sk_omp)
2748 error ("invalid exit from OpenMP structured block");
2754 /* Define a label, specifying the location in the source file.
2755 Return the LABEL_DECL node for the label. */
2758 define_label (location_t location, tree name)
2760 struct named_label_entry *ent, dummy;
2761 struct cp_binding_level *p;
2764 timevar_push (TV_NAME_LOOKUP);
2766 decl = lookup_label (name);
2768 dummy.label_decl = decl;
2769 ent = (struct named_label_entry *) htab_find (named_labels, &dummy);
2770 gcc_assert (ent != NULL);
2772 /* After labels, make any new cleanups in the function go into their
2773 own new (temporary) binding contour. */
2774 for (p = current_binding_level;
2775 p->kind != sk_function_parms;
2777 p->more_cleanups_ok = 0;
2779 if (name == get_identifier ("wchar_t"))
2780 permerror (input_location, "label named wchar_t");
2782 if (DECL_INITIAL (decl) != NULL_TREE)
2784 error ("duplicate label %qD", decl);
2785 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
2789 struct named_label_use_entry *use;
2791 /* Mark label as having been defined. */
2792 DECL_INITIAL (decl) = error_mark_node;
2793 /* Say where in the source. */
2794 DECL_SOURCE_LOCATION (decl) = location;
2796 ent->binding_level = current_binding_level;
2797 ent->names_in_scope = current_binding_level->names;
2799 for (use = ent->uses; use ; use = use->next)
2800 check_previous_goto (decl, use);
2804 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
2809 struct cp_binding_level *level;
2810 struct cp_switch *next;
2811 /* The SWITCH_STMT being built. */
2813 /* A splay-tree mapping the low element of a case range to the high
2814 element, or NULL_TREE if there is no high element. Used to
2815 determine whether or not a new case label duplicates an old case
2816 label. We need a tree, rather than simply a hash table, because
2817 of the GNU case range extension. */
2821 /* A stack of the currently active switch statements. The innermost
2822 switch statement is on the top of the stack. There is no need to
2823 mark the stack for garbage collection because it is only active
2824 during the processing of the body of a function, and we never
2825 collect at that point. */
2827 static struct cp_switch *switch_stack;
2829 /* Called right after a switch-statement condition is parsed.
2830 SWITCH_STMT is the switch statement being parsed. */
2833 push_switch (tree switch_stmt)
2835 struct cp_switch *p = XNEW (struct cp_switch);
2836 p->level = current_binding_level;
2837 p->next = switch_stack;
2838 p->switch_stmt = switch_stmt;
2839 p->cases = splay_tree_new (case_compare, NULL, NULL);
2846 struct cp_switch *cs = switch_stack;
2847 location_t switch_location;
2849 /* Emit warnings as needed. */
2850 if (EXPR_HAS_LOCATION (cs->switch_stmt))
2851 switch_location = EXPR_LOCATION (cs->switch_stmt);
2853 switch_location = input_location;
2854 if (!processing_template_decl)
2855 c_do_switch_warnings (cs->cases, switch_location,
2856 SWITCH_STMT_TYPE (cs->switch_stmt),
2857 SWITCH_STMT_COND (cs->switch_stmt));
2859 splay_tree_delete (cs->cases);
2860 switch_stack = switch_stack->next;
2864 /* Note that we've seen a definition of a case label, and complain if this
2865 is a bad place for one. */
2868 finish_case_label (location_t loc, tree low_value, tree high_value)
2871 struct cp_binding_level *p;
2873 if (processing_template_decl)
2877 /* For templates, just add the case label; we'll do semantic
2878 analysis at instantiation-time. */
2879 label = build_decl (loc, LABEL_DECL, NULL_TREE, NULL_TREE);
2880 return add_stmt (build_case_label (loc, low_value, high_value, label));
2883 /* Find the condition on which this switch statement depends. */
2884 cond = SWITCH_STMT_COND (switch_stack->switch_stmt);
2885 if (cond && TREE_CODE (cond) == TREE_LIST)
2886 cond = TREE_VALUE (cond);
2888 if (!check_switch_goto (switch_stack->level))
2889 return error_mark_node;
2891 r = c_add_case_label (loc, switch_stack->cases, cond,
2892 SWITCH_STMT_TYPE (switch_stack->switch_stmt),
2893 low_value, high_value);
2895 /* After labels, make any new cleanups in the function go into their
2896 own new (temporary) binding contour. */
2897 for (p = current_binding_level;
2898 p->kind != sk_function_parms;
2900 p->more_cleanups_ok = 0;
2905 /* Hash a TYPENAME_TYPE. K is really of type `tree'. */
2908 typename_hash (const void* k)
2911 const_tree const t = (const_tree) k;
2913 hash = (htab_hash_pointer (TYPE_CONTEXT (t))
2914 ^ htab_hash_pointer (DECL_NAME (TYPE_NAME (t))));
2919 typedef struct typename_info {
2927 /* Compare two TYPENAME_TYPEs. K1 is really of type `tree', K2 is
2928 really of type `typename_info*' */
2931 typename_compare (const void * k1, const void * k2)
2933 const_tree const t1 = (const_tree) k1;
2934 const typename_info *const t2 = (const typename_info *) k2;
2936 return (DECL_NAME (TYPE_NAME (t1)) == t2->name
2937 && TYPE_CONTEXT (t1) == t2->scope
2938 && TYPENAME_TYPE_FULLNAME (t1) == t2->template_id
2939 && TYPENAME_IS_ENUM_P (t1) == t2->enum_p
2940 && TYPENAME_IS_CLASS_P (t1) == t2->class_p);
2943 /* Build a TYPENAME_TYPE. If the type is `typename T::t', CONTEXT is
2944 the type of `T', NAME is the IDENTIFIER_NODE for `t'.
2946 Returns the new TYPENAME_TYPE. */
2948 static GTY ((param_is (union tree_node))) htab_t typename_htab;
2951 build_typename_type (tree context, tree name, tree fullname,
2952 enum tag_types tag_type)
2960 if (typename_htab == NULL)
2961 typename_htab = htab_create_ggc (61, &typename_hash,
2962 &typename_compare, NULL);
2964 ti.scope = FROB_CONTEXT (context);
2966 ti.template_id = fullname;
2967 ti.enum_p = tag_type == enum_type;
2968 ti.class_p = (tag_type == class_type
2969 || tag_type == record_type
2970 || tag_type == union_type);
2971 hash = (htab_hash_pointer (ti.scope)
2972 ^ htab_hash_pointer (ti.name));
2974 /* See if we already have this type. */
2975 e = htab_find_slot_with_hash (typename_htab, &ti, hash, INSERT);
2980 /* Build the TYPENAME_TYPE. */
2981 t = cxx_make_type (TYPENAME_TYPE);
2982 TYPE_CONTEXT (t) = ti.scope;
2983 TYPENAME_TYPE_FULLNAME (t) = ti.template_id;
2984 TYPENAME_IS_ENUM_P (t) = ti.enum_p;
2985 TYPENAME_IS_CLASS_P (t) = ti.class_p;
2987 /* Build the corresponding TYPE_DECL. */
2988 d = build_decl (input_location, TYPE_DECL, name, t);
2989 TYPE_NAME (TREE_TYPE (d)) = d;
2990 TYPE_STUB_DECL (TREE_TYPE (d)) = d;
2991 DECL_CONTEXT (d) = FROB_CONTEXT (context);
2992 DECL_ARTIFICIAL (d) = 1;
2994 /* Store it in the hash table. */
2997 /* TYPENAME_TYPEs must always be compared structurally, because
2998 they may or may not resolve down to another type depending on
2999 the currently open classes. */
3000 SET_TYPE_STRUCTURAL_EQUALITY (t);
3006 /* Resolve `typename CONTEXT::NAME'. TAG_TYPE indicates the tag
3007 provided to name the type. Returns an appropriate type, unless an
3008 error occurs, in which case error_mark_node is returned. If we
3009 locate a non-artificial TYPE_DECL and TF_KEEP_TYPE_DECL is set, we
3010 return that, rather than the _TYPE it corresponds to, in other
3011 cases we look through the type decl. If TF_ERROR is set, complain
3012 about errors, otherwise be quiet. */
3015 make_typename_type (tree context, tree name, enum tag_types tag_type,
3016 tsubst_flags_t complain)
3022 if (name == error_mark_node
3023 || context == NULL_TREE
3024 || context == error_mark_node)
3025 return error_mark_node;
3029 if (!(TYPE_LANG_SPECIFIC (name)
3030 && (CLASSTYPE_IS_TEMPLATE (name)
3031 || CLASSTYPE_USE_TEMPLATE (name))))
3032 name = TYPE_IDENTIFIER (name);
3034 /* Create a TEMPLATE_ID_EXPR for the type. */
3035 name = build_nt (TEMPLATE_ID_EXPR,
3036 CLASSTYPE_TI_TEMPLATE (name),
3037 CLASSTYPE_TI_ARGS (name));
3039 else if (TREE_CODE (name) == TYPE_DECL)
3040 name = DECL_NAME (name);
3044 if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
3046 name = TREE_OPERAND (name, 0);
3047 if (TREE_CODE (name) == TEMPLATE_DECL)
3048 name = TREE_OPERAND (fullname, 0) = DECL_NAME (name);
3049 else if (TREE_CODE (name) == OVERLOAD)
3051 error ("%qD is not a type", name);
3052 return error_mark_node;
3055 if (TREE_CODE (name) == TEMPLATE_DECL)
3057 error ("%qD used without template parameters", name);
3058 return error_mark_node;
3060 gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
3061 gcc_assert (TYPE_P (context));
3063 if (!MAYBE_CLASS_TYPE_P (context))
3065 if (complain & tf_error)
3066 error ("%q#T is not a class", context);
3067 return error_mark_node;
3070 /* When the CONTEXT is a dependent type, NAME could refer to a
3071 dependent base class of CONTEXT. But look inside it anyway
3072 if CONTEXT is a currently open scope, in case it refers to a
3073 member of the current instantiation or a non-dependent base;
3074 lookup will stop when we hit a dependent base. */
3075 if (!dependent_scope_p (context))
3076 /* We should only set WANT_TYPE when we're a nested typename type.
3077 Then we can give better diagnostics if we find a non-type. */
3078 t = lookup_field (context, name, 2, /*want_type=*/true);
3082 if ((!t || TREE_CODE (t) == TREE_LIST) && dependent_type_p (context))
3083 return build_typename_type (context, name, fullname, tag_type);
3085 want_template = TREE_CODE (fullname) == TEMPLATE_ID_EXPR;
3089 if (complain & tf_error)
3090 error (want_template ? "no class template named %q#T in %q#T"
3091 : "no type named %q#T in %q#T", name, context);
3092 return error_mark_node;
3095 /* Pull out the template from an injected-class-name (or multiple). */
3097 t = maybe_get_template_decl_from_type_decl (t);
3099 if (TREE_CODE (t) == TREE_LIST)
3101 if (complain & tf_error)
3103 error ("lookup of %qT in %qT is ambiguous", name, context);
3104 print_candidates (t);
3106 return error_mark_node;
3109 if (want_template && !DECL_CLASS_TEMPLATE_P (t))
3111 if (complain & tf_error)
3112 error ("%<typename %T::%D%> names %q#T, which is not a class template",
3114 return error_mark_node;
3116 if (!want_template && TREE_CODE (t) != TYPE_DECL)
3118 if (complain & tf_error)
3119 error ("%<typename %T::%D%> names %q#T, which is not a type",
3121 return error_mark_node;
3124 if (complain & tf_error)
3125 perform_or_defer_access_check (TYPE_BINFO (context), t, t);
3127 /* If we are currently parsing a template and if T is a typedef accessed
3128 through CONTEXT then we need to remember and check access of T at
3129 template instantiation time. */
3130 add_typedef_to_current_template_for_access_check (t, context, input_location);
3133 return lookup_template_class (t, TREE_OPERAND (fullname, 1),
3135 /*entering_scope=*/0,
3136 tf_warning_or_error | tf_user);
3138 if (DECL_ARTIFICIAL (t) || !(complain & tf_keep_type_decl))
3144 /* Resolve `CONTEXT::template NAME'. Returns a TEMPLATE_DECL if the name
3145 can be resolved or an UNBOUND_CLASS_TEMPLATE, unless an error occurs,
3146 in which case error_mark_node is returned.
3148 If PARM_LIST is non-NULL, also make sure that the template parameter
3149 list of TEMPLATE_DECL matches.
3151 If COMPLAIN zero, don't complain about any errors that occur. */
3154 make_unbound_class_template (tree context, tree name, tree parm_list,
3155 tsubst_flags_t complain)
3161 name = TYPE_IDENTIFIER (name);
3162 else if (DECL_P (name))
3163 name = DECL_NAME (name);
3164 gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
3166 if (!dependent_type_p (context)
3167 || currently_open_class (context))
3169 tree tmpl = NULL_TREE;
3171 if (MAYBE_CLASS_TYPE_P (context))
3172 tmpl = lookup_field (context, name, 0, false);
3174 if (!tmpl || !DECL_CLASS_TEMPLATE_P (tmpl))
3176 if (complain & tf_error)
3177 error ("no class template named %q#T in %q#T", name, context);
3178 return error_mark_node;
3182 && !comp_template_parms (DECL_TEMPLATE_PARMS (tmpl), parm_list))
3184 if (complain & tf_error)
3186 error ("template parameters do not match template");
3187 error ("%q+D declared here", tmpl);
3189 return error_mark_node;
3192 if (complain & tf_error)
3193 perform_or_defer_access_check (TYPE_BINFO (context), tmpl, tmpl);
3198 /* Build the UNBOUND_CLASS_TEMPLATE. */
3199 t = cxx_make_type (UNBOUND_CLASS_TEMPLATE);
3200 TYPE_CONTEXT (t) = FROB_CONTEXT (context);
3201 TREE_TYPE (t) = NULL_TREE;
3202 SET_TYPE_STRUCTURAL_EQUALITY (t);
3204 /* Build the corresponding TEMPLATE_DECL. */
3205 d = build_decl (input_location, TEMPLATE_DECL, name, t);
3206 TYPE_NAME (TREE_TYPE (d)) = d;
3207 TYPE_STUB_DECL (TREE_TYPE (d)) = d;
3208 DECL_CONTEXT (d) = FROB_CONTEXT (context);
3209 DECL_ARTIFICIAL (d) = 1;
3210 DECL_TEMPLATE_PARMS (d) = parm_list;
3217 /* Push the declarations of builtin types into the namespace.
3218 RID_INDEX is the index of the builtin type in the array
3219 RID_POINTERS. NAME is the name used when looking up the builtin
3220 type. TYPE is the _TYPE node for the builtin type. */
3223 record_builtin_type (enum rid rid_index,
3227 tree rname = NULL_TREE, tname = NULL_TREE;
3228 tree tdecl = NULL_TREE;
3230 if ((int) rid_index < (int) RID_MAX)
3231 rname = ridpointers[(int) rid_index];
3233 tname = get_identifier (name);
3235 /* The calls to SET_IDENTIFIER_GLOBAL_VALUE below should be
3236 eliminated. Built-in types should not be looked up name; their
3237 names are keywords that the parser can recognize. However, there
3238 is code in c-common.c that uses identifier_global_value to look
3239 up built-in types by name. */
3242 tdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, tname, type);
3243 DECL_ARTIFICIAL (tdecl) = 1;
3244 SET_IDENTIFIER_GLOBAL_VALUE (tname, tdecl);
3250 tdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, rname, type);
3251 DECL_ARTIFICIAL (tdecl) = 1;
3253 SET_IDENTIFIER_GLOBAL_VALUE (rname, tdecl);
3256 if (!TYPE_NAME (type))
3257 TYPE_NAME (type) = tdecl;
3260 debug_hooks->type_decl (tdecl, 0);
3263 /* Record one of the standard Java types.
3264 * Declare it as having the given NAME.
3265 * If SIZE > 0, it is the size of one of the integral types;
3266 * otherwise it is the negative of the size of one of the other types. */
3269 record_builtin_java_type (const char* name, int size)
3273 type = build_nonstandard_integer_type (size, 0);
3274 else if (size > -32)
3277 /* "__java_char" or ""__java_boolean". */
3278 type = build_nonstandard_integer_type (-size, 1);
3279 /* Get the signed type cached and attached to the unsigned type,
3280 so it doesn't get garbage-collected at "random" times,
3281 causing potential codegen differences out of different UIDs
3282 and different alias set numbers. */
3283 stype = build_nonstandard_integer_type (-size, 0);
3284 TREE_CHAIN (type) = stype;
3285 /*if (size == -1) TREE_SET_CODE (type, BOOLEAN_TYPE);*/
3288 { /* "__java_float" or ""__java_double". */
3289 type = make_node (REAL_TYPE);
3290 TYPE_PRECISION (type) = - size;
3293 record_builtin_type (RID_MAX, name, type);
3294 decl = TYPE_NAME (type);
3296 /* Suppress generate debug symbol entries for these types,
3297 since for normal C++ they are just clutter.
3298 However, push_lang_context undoes this if extern "Java" is seen. */
3299 DECL_IGNORED_P (decl) = 1;
3301 TYPE_FOR_JAVA (type) = 1;
3305 /* Push a type into the namespace so that the back ends ignore it. */
3308 record_unknown_type (tree type, const char* name)
3310 tree decl = pushdecl (build_decl (UNKNOWN_LOCATION,
3311 TYPE_DECL, get_identifier (name), type));
3312 /* Make sure the "unknown type" typedecl gets ignored for debug info. */
3313 DECL_IGNORED_P (decl) = 1;
3314 TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
3315 TYPE_SIZE (type) = TYPE_SIZE (void_type_node);
3316 TYPE_ALIGN (type) = 1;
3317 TYPE_USER_ALIGN (type) = 0;
3318 SET_TYPE_MODE (type, TYPE_MODE (void_type_node));
3321 /* A string for which we should create an IDENTIFIER_NODE at
3324 typedef struct predefined_identifier
3326 /* The name of the identifier. */
3327 const char *const name;
3328 /* The place where the IDENTIFIER_NODE should be stored. */
3330 /* Nonzero if this is the name of a constructor or destructor. */
3331 const int ctor_or_dtor_p;
3332 } predefined_identifier;
3334 /* Create all the predefined identifiers. */
3337 initialize_predefined_identifiers (void)
3339 const predefined_identifier *pid;
3341 /* A table of identifiers to create at startup. */
3342 static const predefined_identifier predefined_identifiers[] = {
3343 { "C++", &lang_name_cplusplus, 0 },
3344 { "C", &lang_name_c, 0 },
3345 { "Java", &lang_name_java, 0 },
3346 /* Some of these names have a trailing space so that it is
3347 impossible for them to conflict with names written by users. */
3348 { "__ct ", &ctor_identifier, 1 },
3349 { "__base_ctor ", &base_ctor_identifier, 1 },
3350 { "__comp_ctor ", &complete_ctor_identifier, 1 },
3351 { "__dt ", &dtor_identifier, 1 },
3352 { "__comp_dtor ", &complete_dtor_identifier, 1 },
3353 { "__base_dtor ", &base_dtor_identifier, 1 },
3354 { "__deleting_dtor ", &deleting_dtor_identifier, 1 },
3355 { IN_CHARGE_NAME, &in_charge_identifier, 0 },
3356 { "nelts", &nelts_identifier, 0 },
3357 { THIS_NAME, &this_identifier, 0 },
3358 { VTABLE_DELTA_NAME, &delta_identifier, 0 },
3359 { VTABLE_PFN_NAME, &pfn_identifier, 0 },
3360 { "_vptr", &vptr_identifier, 0 },
3361 { "__vtt_parm", &vtt_parm_identifier, 0 },
3362 { "::", &global_scope_name, 0 },
3363 { "std", &std_identifier, 0 },
3367 for (pid = predefined_identifiers; pid->name; ++pid)
3369 *pid->node = get_identifier (pid->name);
3370 if (pid->ctor_or_dtor_p)
3371 IDENTIFIER_CTOR_OR_DTOR_P (*pid->node) = 1;
3375 /* Create the predefined scalar types of C,
3376 and some nodes representing standard constants (0, 1, (void *)0).
3377 Initialize the global binding level.
3378 Make definitions for built-in primitive functions. */
3381 cxx_init_decl_processing (void)
3384 tree void_ftype_ptr;
3386 build_common_tree_nodes (flag_signed_char);
3388 /* Create all the identifiers we need. */
3389 initialize_predefined_identifiers ();
3391 /* Create the global variables. */
3392 push_to_top_level ();
3394 current_function_decl = NULL_TREE;
3395 current_binding_level = NULL;
3396 /* Enter the global namespace. */
3397 gcc_assert (global_namespace == NULL_TREE);
3398 global_namespace = build_lang_decl (NAMESPACE_DECL, global_scope_name,
3400 TREE_PUBLIC (global_namespace) = 1;
3401 begin_scope (sk_namespace, global_namespace);
3403 current_lang_name = NULL_TREE;
3405 if (flag_visibility_ms_compat)
3406 default_visibility = VISIBILITY_HIDDEN;
3409 current_lang_name = lang_name_c;
3411 /* Create the `std' namespace. */
3412 push_namespace (std_identifier);
3413 std_node = current_namespace;
3416 c_common_nodes_and_builtins ();
3418 java_byte_type_node = record_builtin_java_type ("__java_byte", 8);
3419 java_short_type_node = record_builtin_java_type ("__java_short", 16);
3420 java_int_type_node = record_builtin_java_type ("__java_int", 32);
3421 java_long_type_node = record_builtin_java_type ("__java_long", 64);
3422 java_float_type_node = record_builtin_java_type ("__java_float", -32);
3423 java_double_type_node = record_builtin_java_type ("__java_double", -64);
3424 java_char_type_node = record_builtin_java_type ("__java_char", -16);
3425 java_boolean_type_node = record_builtin_java_type ("__java_boolean", -1);
3427 integer_two_node = build_int_cst (NULL_TREE, 2);
3428 integer_three_node = build_int_cst (NULL_TREE, 3);
3430 record_builtin_type (RID_BOOL, "bool", boolean_type_node);
3431 truthvalue_type_node = boolean_type_node;
3432 truthvalue_false_node = boolean_false_node;
3433 truthvalue_true_node = boolean_true_node;
3435 empty_except_spec = build_tree_list (NULL_TREE, NULL_TREE);
3438 record_builtin_type (RID_MAX, NULL, string_type_node);
3441 delta_type_node = ptrdiff_type_node;
3442 vtable_index_type = ptrdiff_type_node;
3444 vtt_parm_type = build_pointer_type (const_ptr_type_node);
3445 void_ftype = build_function_type (void_type_node, void_list_node);
3446 void_ftype_ptr = build_function_type (void_type_node,
3447 tree_cons (NULL_TREE,
3451 = build_exception_variant (void_ftype_ptr, empty_except_spec);
3453 /* C++ extensions */
3455 unknown_type_node = make_node (LANG_TYPE);
3456 record_unknown_type (unknown_type_node, "unknown type");
3458 /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node. */
3459 TREE_TYPE (unknown_type_node) = unknown_type_node;
3461 /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same
3463 TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
3464 TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
3466 init_list_type_node = make_node (LANG_TYPE);
3467 record_unknown_type (init_list_type_node, "init list");
3470 /* Make sure we get a unique function type, so we can give
3471 its pointer type a name. (This wins for gdb.) */
3472 tree vfunc_type = make_node (FUNCTION_TYPE);
3473 TREE_TYPE (vfunc_type) = integer_type_node;
3474 TYPE_ARG_TYPES (vfunc_type) = NULL_TREE;
3475 layout_type (vfunc_type);
3477 vtable_entry_type = build_pointer_type (vfunc_type);
3479 record_builtin_type (RID_MAX, VTBL_PTR_TYPE, vtable_entry_type);
3482 = build_cplus_array_type (vtable_entry_type, NULL_TREE);
3483 layout_type (vtbl_type_node);
3484 vtbl_type_node = cp_build_qualified_ty