1 /* Functions related to building classes and their related objects.
2 Copyright (C) 1987, 92-99, 2000 Free Software Foundation, Inc.
3 Contributed by Michael Tiemann (tiemann@cygnus.com)
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 /* High-level class interface. */
37 #define obstack_chunk_alloc xmalloc
38 #define obstack_chunk_free free
40 /* This is how we tell when two virtual member functions are really the
42 #define SAME_FN(FN1DECL, FN2DECL) (DECL_ASSEMBLER_NAME (FN1DECL) == DECL_ASSEMBLER_NAME (FN2DECL))
44 extern void set_class_shadows PROTO ((tree));
46 /* The number of nested classes being processed. If we are not in the
47 scope of any class, this is zero. */
49 int current_class_depth;
51 /* In order to deal with nested classes, we keep a stack of classes.
52 The topmost entry is the innermost class, and is the entry at index
53 CURRENT_CLASS_DEPTH */
55 typedef struct class_stack_node {
56 /* The name of the class. */
59 /* The _TYPE node for the class. */
62 /* The access specifier pending for new declarations in the scope of
66 /* If were defining TYPE, the names used in this class. */
67 splay_tree names_used;
68 }* class_stack_node_t;
70 /* The stack itself. This is an dynamically resized array. The
71 number of elements allocated is CURRENT_CLASS_STACK_SIZE. */
72 static int current_class_stack_size;
73 static class_stack_node_t current_class_stack;
75 static tree get_vfield_name PROTO((tree));
76 static void finish_struct_anon PROTO((tree));
77 static tree build_vbase_pointer PROTO((tree, tree));
78 static tree build_vtable_entry PROTO((tree, tree));
79 static tree get_vtable_name PROTO((tree));
80 static tree get_derived_offset PROTO((tree, tree));
81 static tree get_basefndecls PROTO((tree, tree));
82 static void set_rtti_entry PROTO((tree, tree, tree));
83 static void build_vtable PROTO((tree, tree));
84 static void prepare_fresh_vtable PROTO((tree, tree));
85 static tree dfs_fixup_vtable_deltas PROTO((tree, void *));
86 static tree dfs_finish_vtbls PROTO((tree, void *));
87 static void finish_vtbls PROTO((tree));
88 static void modify_vtable_entry PROTO((tree, tree, tree));
89 static tree get_vtable_entry_n PROTO((tree, unsigned HOST_WIDE_INT));
90 static void add_virtual_function PROTO((tree *, tree *, int *, tree, tree));
91 static tree delete_duplicate_fields_1 PROTO((tree, tree));
92 static void delete_duplicate_fields PROTO((tree));
93 static void finish_struct_bits PROTO((tree));
94 static int alter_access PROTO((tree, tree, tree, tree));
95 static void handle_using_decl PROTO((tree, tree));
96 static int overrides PROTO((tree, tree));
97 static int strictly_overrides PROTO((tree, tree));
98 static void merge_overrides PROTO((tree, tree, int, tree));
99 static void override_one_vtable PROTO((tree, tree, tree));
100 static void mark_overriders PROTO((tree, tree));
101 static void check_for_override PROTO((tree, tree));
102 static tree dfs_get_class_offset PROTO((tree, void *));
103 static tree get_class_offset PROTO((tree, tree, tree, tree));
104 static void modify_one_vtable PROTO((tree, tree, tree));
105 static tree dfs_modify_vtables PROTO((tree, void *));
106 static void modify_all_vtables PROTO((tree, tree));
107 static void determine_primary_base PROTO((tree, int *));
108 static void finish_struct_methods PROTO((tree));
109 static void maybe_warn_about_overly_private_class PROTO ((tree));
110 static int field_decl_cmp PROTO ((const tree *, const tree *));
111 static int method_name_cmp PROTO ((const tree *, const tree *));
112 static tree add_implicitly_declared_members PROTO((tree, int, int, int));
113 static tree fixed_type_or_null PROTO((tree, int *));
114 static tree resolve_address_of_overloaded_function PROTO((tree, tree, int,
116 static void build_vtable_entry_ref PROTO((tree, tree, tree));
117 static tree build_vtable_entry_for_fn PROTO((tree, tree));
118 static tree build_vtbl_initializer PROTO((tree));
119 static int count_fields PROTO((tree));
120 static int add_fields_to_vec PROTO((tree, tree, int));
121 static void check_bitfield_decl PROTO((tree));
122 static void check_field_decl PROTO((tree, tree, int *, int *, int *, int *));
123 static void check_field_decls PROTO((tree, tree *, int *, int *, int *,
125 static int avoid_overlap PROTO((tree, tree, int *));
126 static tree build_base_field PROTO((tree, tree, int *, int *, unsigned int *));
127 static tree build_base_fields PROTO((tree, int *));
128 static tree build_vbase_pointer_fields PROTO((tree, int *));
129 static tree build_vtbl_or_vbase_field PROTO((tree, tree, tree, tree, int *));
130 static void check_methods PROTO((tree));
131 static void remove_zero_width_bit_fields PROTO((tree));
132 static void check_bases PROTO((tree, int *, int *, int *));
133 static void check_bases_and_members PROTO((tree, int *));
134 static void create_vtable_ptr PROTO((tree, int *, int *, tree *, tree *));
135 static void layout_class_type PROTO((tree, int *, int *, tree *, tree *));
136 static void fixup_pending_inline PROTO((struct pending_inline *));
137 static void fixup_inline_methods PROTO((tree));
138 static void set_primary_base PROTO((tree, int, int *));
139 static tree dfs_propagate_binfo_offsets PROTO((tree, void *));
140 static void propagate_binfo_offsets PROTO((tree, tree));
141 static void layout_basetypes PROTO((tree));
142 static void layout_virtual_bases PROTO((tree));
143 static void remove_base_field PROTO((tree, tree, tree *));
144 static void remove_base_fields PROTO((tree));
145 static tree dfs_set_offset_for_shared_vbases PROTO((tree, void *));
146 static tree dfs_set_offset_for_unshared_vbases PROTO((tree, void *));
148 /* Variables shared between class.c and call.c. */
150 #ifdef GATHER_STATISTICS
152 int n_vtable_entries = 0;
153 int n_vtable_searches = 0;
154 int n_vtable_elems = 0;
155 int n_convert_harshness = 0;
156 int n_compute_conversion_costs = 0;
157 int n_build_method_call = 0;
158 int n_inner_fields_searched = 0;
161 /* Virtual baseclass things. */
164 build_vbase_pointer (exp, type)
168 FORMAT_VBASE_NAME (name, type);
170 return build_component_ref (exp, get_identifier (name), NULL_TREE, 0);
174 /* Is the type of the EXPR, the complete type of the object?
175 If we are going to be wrong, we must be conservative, and return 0. */
178 complete_type_p (expr)
181 tree type = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
184 switch (TREE_CODE (expr))
191 expr = TREE_OPERAND (expr, 0);
195 if (! TREE_HAS_CONSTRUCTOR (expr))
197 /* fall through... */
200 if (TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
201 && IS_AGGR_TYPE (TREE_TYPE (TREE_TYPE (expr)))
202 && TYPE_MAIN_VARIANT (TREE_TYPE (expr)) == type)
204 /* fall through... */
207 if (IS_AGGR_TYPE (TREE_TYPE (expr))
208 && TYPE_MAIN_VARIANT (TREE_TYPE (expr)) == type)
210 /* fall through... */
221 /* Build multi-level access to EXPR using hierarchy path PATH.
222 CODE is PLUS_EXPR if we are going with the grain,
223 and MINUS_EXPR if we are not (in which case, we cannot traverse
224 virtual baseclass links).
226 TYPE is the type we want this path to have on exit.
228 NONNULL is non-zero if we know (for any reason) that EXPR is
229 not, in fact, zero. */
232 build_vbase_path (code, type, expr, path, nonnull)
234 tree type, expr, path;
237 register int changed = 0;
238 tree last = NULL_TREE, last_virtual = NULL_TREE;
240 tree null_expr = 0, nonnull_expr;
242 tree offset = integer_zero_node;
244 if (BINFO_INHERITANCE_CHAIN (path) == NULL_TREE)
245 return build1 (NOP_EXPR, type, expr);
247 /* We could do better if we had additional logic to convert back to the
248 unconverted type (the static type of the complete object), and then
249 convert back to the type we want. Until that is done, we only optimize
250 if the complete type is the same type as expr has. */
251 fixed_type_p = resolves_to_fixed_type_p (expr, &nonnull);
253 if (!fixed_type_p && TREE_SIDE_EFFECTS (expr))
254 expr = save_expr (expr);
257 if (BINFO_INHERITANCE_CHAIN (path))
258 path = reverse_path (path);
260 basetype = BINFO_TYPE (path);
264 if (TREE_VIA_VIRTUAL (path))
266 last_virtual = BINFO_TYPE (path);
267 if (code == PLUS_EXPR)
269 changed = ! fixed_type_p;
275 /* We already check for ambiguous things in the caller, just
279 tree binfo = get_binfo (last, TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (nonnull_expr))), 0);
280 nonnull_expr = convert_pointer_to_real (binfo, nonnull_expr);
282 ind = build_indirect_ref (nonnull_expr, NULL_PTR);
283 nonnull_expr = build_vbase_pointer (ind, last_virtual);
285 && TREE_CODE (type) == POINTER_TYPE
286 && null_expr == NULL_TREE)
288 null_expr = build1 (NOP_EXPR, build_pointer_type (last_virtual), integer_zero_node);
289 expr = build (COND_EXPR, build_pointer_type (last_virtual),
290 build (EQ_EXPR, boolean_type_node, expr,
292 null_expr, nonnull_expr);
295 /* else we'll figure out the offset below. */
297 /* Happens in the case of parse errors. */
298 if (nonnull_expr == error_mark_node)
299 return error_mark_node;
303 cp_error ("cannot cast up from virtual baseclass `%T'",
305 return error_mark_node;
309 path = BINFO_INHERITANCE_CHAIN (path);
311 /* LAST is now the last basetype assoc on the path. */
313 /* A pointer to a virtual base member of a non-null object
314 is non-null. Therefore, we only need to test for zeroness once.
315 Make EXPR the canonical expression to deal with here. */
318 TREE_OPERAND (expr, 2) = nonnull_expr;
319 TREE_TYPE (expr) = TREE_TYPE (TREE_OPERAND (expr, 1))
320 = TREE_TYPE (nonnull_expr);
325 /* If we go through any virtual base pointers, make sure that
326 casts to BASETYPE from the last virtual base class use
327 the right value for BASETYPE. */
330 tree intype = TREE_TYPE (TREE_TYPE (expr));
331 if (TYPE_MAIN_VARIANT (intype) != BINFO_TYPE (last))
333 tree binfo = get_binfo (last, TYPE_MAIN_VARIANT (intype), 0);
334 offset = BINFO_OFFSET (binfo);
338 offset = BINFO_OFFSET (last);
340 if (TREE_INT_CST_LOW (offset))
342 /* Bash types to make the backend happy. */
343 offset = cp_convert (type, offset);
345 /* This shouldn't be necessary. (mrs) */
346 expr = build1 (NOP_EXPR, type, expr);
349 /* If expr might be 0, we need to preserve that zeroness. */
353 TREE_TYPE (null_expr) = type;
355 null_expr = build1 (NOP_EXPR, type, integer_zero_node);
356 if (TREE_SIDE_EFFECTS (expr))
357 expr = save_expr (expr);
359 return build (COND_EXPR, type,
360 build (EQ_EXPR, boolean_type_node, expr, integer_zero_node),
362 build (code, type, expr, offset));
364 else return build (code, type, expr, offset);
367 /* Cannot change the TREE_TYPE of a NOP_EXPR here, since it may
368 be used multiple times in initialization of multiple inheritance. */
371 TREE_TYPE (expr) = type;
375 return build1 (NOP_EXPR, type, expr);
378 /* Virtual function things. */
380 /* Build an entry in the virtual function table.
381 DELTA is the offset for the `this' pointer.
382 PFN is an ADDR_EXPR containing a pointer to the virtual function.
383 Note that the index (DELTA2) in the virtual function table
387 build_vtable_entry (delta, pfn)
390 if (flag_vtable_thunks)
392 HOST_WIDE_INT idelta = TREE_INT_CST_LOW (delta);
393 if (idelta && ! DECL_PURE_VIRTUAL_P (TREE_OPERAND (pfn, 0)))
395 pfn = build1 (ADDR_EXPR, vtable_entry_type,
396 make_thunk (pfn, idelta));
397 TREE_READONLY (pfn) = 1;
398 TREE_CONSTANT (pfn) = 1;
400 #ifdef GATHER_STATISTICS
401 n_vtable_entries += 1;
407 extern int flag_huge_objects;
408 tree elems = tree_cons (NULL_TREE, delta,
409 tree_cons (NULL_TREE, integer_zero_node,
410 build_expr_list (NULL_TREE, pfn)));
411 tree entry = build (CONSTRUCTOR, vtable_entry_type, NULL_TREE, elems);
413 /* DELTA used to be constructed by `size_int' and/or size_binop,
414 which caused overflow problems when it was negative. That should
417 if (! int_fits_type_p (delta, delta_type_node))
419 if (flag_huge_objects)
420 sorry ("object size exceeds built-in limit for virtual function table implementation");
422 sorry ("object size exceeds normal limit for virtual function table implementation, recompile all source and use -fhuge-objects");
425 TREE_CONSTANT (entry) = 1;
426 TREE_STATIC (entry) = 1;
427 TREE_READONLY (entry) = 1;
429 #ifdef GATHER_STATISTICS
430 n_vtable_entries += 1;
437 /* Build a vtable entry for FNDECL. DELTA is the amount by which we
438 must adjust the this pointer when calling F. */
441 build_vtable_entry_for_fn (delta, fndecl)
447 /* Take the address of the function, considering it to be of an
448 appropriate generic type. */
449 pfn = build1 (ADDR_EXPR, vfunc_ptr_type_node, fndecl);
450 /* The address of a function can't change. */
451 TREE_CONSTANT (pfn) = 1;
452 /* Now build the vtable entry itself. */
453 return build_vtable_entry (delta, pfn);
456 /* We want to give the assembler the vtable identifier as well as
457 the offset to the function pointer. So we generate
459 __asm__ __volatile__ (".vtable_entry %c0, %c1"
460 : : "s"(&class_vtable),
461 "i"((long)&vtbl[idx].pfn - (long)&vtbl[0])); */
464 build_vtable_entry_ref (basetype, vtbl, idx)
465 tree basetype, vtbl, idx;
467 static char asm_stmt[] = ".vtable_entry %c0, %c1";
470 s = build_unary_op (ADDR_EXPR, TYPE_BINFO_VTABLE (basetype), 0);
471 s = build_tree_list (build_string (1, "s"), s);
473 i = build_array_ref (vtbl, idx);
474 if (!flag_vtable_thunks)
475 i = build_component_ref (i, pfn_identifier, vtable_entry_type, 0);
476 i = build_c_cast (ptrdiff_type_node, build_unary_op (ADDR_EXPR, i, 0));
477 i2 = build_array_ref (vtbl, build_int_2(0,0));
478 i2 = build_c_cast (ptrdiff_type_node, build_unary_op (ADDR_EXPR, i2, 0));
479 i = build_binary_op (MINUS_EXPR, i, i2);
480 i = build_tree_list (build_string (1, "i"), i);
482 finish_asm_stmt (ridpointers[RID_VOLATILE],
483 build_string (sizeof(asm_stmt)-1, asm_stmt),
484 NULL_TREE, chainon (s, i), NULL_TREE);
487 /* Given an object INSTANCE, return an expression which yields the
488 virtual function vtable element corresponding to INDEX. There are
489 many special cases for INSTANCE which we take care of here, mainly
490 to avoid creating extra tree nodes when we don't have to. */
493 build_vtbl_ref (instance, idx)
497 tree basetype = TREE_TYPE (instance);
499 if (TREE_CODE (basetype) == REFERENCE_TYPE)
500 basetype = TREE_TYPE (basetype);
502 if (instance == current_class_ref)
503 vtbl = build_vfield_ref (instance, basetype);
508 /* Try to figure out what a reference refers to, and
509 access its virtual function table directly. */
510 tree ref = NULL_TREE;
512 if (TREE_CODE (instance) == INDIRECT_REF
513 && TREE_CODE (TREE_TYPE (TREE_OPERAND (instance, 0))) == REFERENCE_TYPE)
514 ref = TREE_OPERAND (instance, 0);
515 else if (TREE_CODE (TREE_TYPE (instance)) == REFERENCE_TYPE)
518 if (ref && TREE_CODE (ref) == VAR_DECL
519 && DECL_INITIAL (ref))
521 tree init = DECL_INITIAL (ref);
523 while (TREE_CODE (init) == NOP_EXPR
524 || TREE_CODE (init) == NON_LVALUE_EXPR)
525 init = TREE_OPERAND (init, 0);
526 if (TREE_CODE (init) == ADDR_EXPR)
528 init = TREE_OPERAND (init, 0);
529 if (IS_AGGR_TYPE (TREE_TYPE (init))
530 && (TREE_CODE (init) == PARM_DECL
531 || TREE_CODE (init) == VAR_DECL))
537 if (IS_AGGR_TYPE (TREE_TYPE (instance))
538 && (TREE_CODE (instance) == RESULT_DECL
539 || TREE_CODE (instance) == PARM_DECL
540 || TREE_CODE (instance) == VAR_DECL))
541 vtbl = TYPE_BINFO_VTABLE (basetype);
543 vtbl = build_vfield_ref (instance, basetype);
546 assemble_external (vtbl);
549 build_vtable_entry_ref (basetype, vtbl, idx);
551 aref = build_array_ref (vtbl, idx);
556 /* Given an object INSTANCE, return an expression which yields the
557 virtual function corresponding to INDEX. There are many special
558 cases for INSTANCE which we take care of here, mainly to avoid
559 creating extra tree nodes when we don't have to. */
562 build_vfn_ref (ptr_to_instptr, instance, idx)
563 tree *ptr_to_instptr, instance;
566 tree aref = build_vtbl_ref (instance, idx);
568 /* When using thunks, there is no extra delta, and we get the pfn
570 if (flag_vtable_thunks)
575 /* Save the intermediate result in a SAVE_EXPR so we don't have to
576 compute each component of the virtual function pointer twice. */
577 if (TREE_CODE (aref) == INDIRECT_REF)
578 TREE_OPERAND (aref, 0) = save_expr (TREE_OPERAND (aref, 0));
581 = build (PLUS_EXPR, TREE_TYPE (*ptr_to_instptr),
583 cp_convert (ptrdiff_type_node,
584 build_component_ref (aref, delta_identifier, NULL_TREE, 0)));
587 return build_component_ref (aref, pfn_identifier, NULL_TREE, 0);
590 /* Return the name of the virtual function table (as an IDENTIFIER_NODE)
591 for the given TYPE. */
594 get_vtable_name (type)
597 tree type_id = build_typename_overload (type);
598 char *buf = (char *) alloca (strlen (VTABLE_NAME_PREFIX)
599 + IDENTIFIER_LENGTH (type_id) + 2);
600 const char *ptr = IDENTIFIER_POINTER (type_id);
602 for (i = 0; ptr[i] == OPERATOR_TYPENAME_FORMAT[i]; i++) ;
604 /* We don't take off the numbers; prepare_fresh_vtable uses the
605 DECL_ASSEMBLER_NAME for the type, which includes the number
606 in `3foo'. If we were to pull them off here, we'd end up with
607 something like `_vt.foo.3bar', instead of a uniform definition. */
608 while (ptr[i] >= '0' && ptr[i] <= '9')
611 sprintf (buf, "%s%s", VTABLE_NAME_PREFIX, ptr+i);
612 return get_identifier (buf);
615 /* Return the offset to the main vtable for a given base BINFO. */
618 get_vfield_offset (binfo)
622 = size_binop (FLOOR_DIV_EXPR,
623 DECL_FIELD_BITPOS (TYPE_VFIELD (BINFO_TYPE (binfo))),
624 size_int (BITS_PER_UNIT));
625 tmp = convert (sizetype, tmp);
626 return size_binop (PLUS_EXPR, tmp, BINFO_OFFSET (binfo));
629 /* Get the offset to the start of the original binfo that we derived
630 this binfo from. If we find TYPE first, return the offset only
631 that far. The shortened search is useful because the this pointer
632 on method calling is expected to point to a DECL_CONTEXT (fndecl)
633 object, and not a baseclass of it. */
636 get_derived_offset (binfo, type)
639 tree offset1 = get_vfield_offset (TYPE_BINFO (BINFO_TYPE (binfo)));
642 while (BINFO_BASETYPES (binfo)
643 && (i=CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo))) != -1)
645 tree binfos = BINFO_BASETYPES (binfo);
646 if (BINFO_TYPE (binfo) == type)
648 binfo = TREE_VEC_ELT (binfos, i);
650 offset2 = get_vfield_offset (TYPE_BINFO (BINFO_TYPE (binfo)));
651 return size_binop (MINUS_EXPR, offset1, offset2);
654 /* Update the rtti info for this class. */
657 set_rtti_entry (virtuals, offset, type)
658 tree virtuals, offset, type;
662 if (CLASSTYPE_COM_INTERFACE (type))
666 fn = get_tinfo_fn_unused (type);
668 /* If someone tries to get RTTI information for a type compiled
669 without RTTI, they're out of luck. By calling __pure_virtual
670 in this case, we give a small clue as to what went wrong. We
671 could consider having a __no_typeinfo function as well, for a
672 more specific hint. */
675 if (flag_vtable_thunks)
677 /* The first slot holds the offset. */
678 TREE_PURPOSE (virtuals) = offset;
680 /* The next node holds the function. */
681 virtuals = TREE_CHAIN (virtuals);
682 offset = integer_zero_node;
685 /* This slot holds the function to call. */
686 TREE_PURPOSE (virtuals) = offset;
687 TREE_VALUE (virtuals) = fn;
690 /* Build a virtual function for type TYPE.
691 If BINFO is non-NULL, build the vtable starting with the initial
692 approximation that it is the same as the one which is the head of
693 the association list. */
696 build_vtable (binfo, type)
699 tree name = get_vtable_name (type);
706 if (BINFO_NEW_VTABLE_MARKED (binfo))
707 /* We have already created a vtable for this base, so there's
708 no need to do it again. */
711 virtuals = copy_list (BINFO_VIRTUALS (binfo));
712 decl = build_lang_decl (VAR_DECL, name,
713 TREE_TYPE (BINFO_VTABLE (binfo)));
715 /* Now do rtti stuff. */
716 offset = get_derived_offset (TYPE_BINFO (type), NULL_TREE);
717 offset = ssize_binop (MINUS_EXPR, integer_zero_node, offset);
718 set_rtti_entry (virtuals, offset, type);
722 virtuals = NULL_TREE;
723 decl = build_lang_decl (VAR_DECL, name, void_type_node);
726 #ifdef GATHER_STATISTICS
728 n_vtable_elems += list_length (virtuals);
731 /* Set TREE_PUBLIC and TREE_EXTERN as appropriate. */
732 import_export_vtable (decl, type, 0);
734 decl = pushdecl_top_level (decl);
735 SET_IDENTIFIER_GLOBAL_VALUE (name, decl);
736 /* Initialize the association list for this type, based
737 on our first approximation. */
738 TYPE_BINFO_VTABLE (type) = decl;
739 TYPE_BINFO_VIRTUALS (type) = virtuals;
741 DECL_ARTIFICIAL (decl) = 1;
742 TREE_STATIC (decl) = 1;
743 #ifndef WRITABLE_VTABLES
744 /* Make them READONLY by default. (mrs) */
745 TREE_READONLY (decl) = 1;
747 /* At one time the vtable info was grabbed 2 words at a time. This
748 fails on sparc unless you have 8-byte alignment. (tiemann) */
749 DECL_ALIGN (decl) = MAX (TYPE_ALIGN (double_type_node),
752 DECL_VIRTUAL_P (decl) = 1;
753 DECL_CONTEXT (decl) = type;
755 binfo = TYPE_BINFO (type);
756 SET_BINFO_NEW_VTABLE_MARKED (binfo);
759 /* Give TYPE a new virtual function table which is initialized
760 with a skeleton-copy of its original initialization. The only
761 entry that changes is the `delta' entry, so we can really
762 share a lot of structure.
764 FOR_TYPE is the derived type which caused this table to
767 BINFO is the type association which provided TYPE for FOR_TYPE.
769 The order in which vtables are built (by calling this function) for
770 an object must remain the same, otherwise a binary incompatibility
774 prepare_fresh_vtable (binfo, for_type)
775 tree binfo, for_type;
778 tree orig_decl = BINFO_VTABLE (binfo);
791 if (BINFO_NEW_VTABLE_MARKED (binfo))
792 /* We already created a vtable for this base. There's no need to
796 basetype = TYPE_MAIN_VARIANT (BINFO_TYPE (binfo));
798 buf2 = TYPE_ASSEMBLER_NAME_STRING (basetype);
799 i = TYPE_ASSEMBLER_NAME_LENGTH (basetype) + 1;
801 /* We know that the vtable that we are going to create doesn't exist
802 yet in the global namespace, and when we finish, it will be
803 pushed into the global namespace. In complex MI hierarchies, we
804 have to loop while the name we are thinking of adding is globally
805 defined, adding more name components to the vtable name as we
806 loop, until the name is unique. This is because in complex MI
807 cases, we might have the same base more than once. This means
808 that the order in which this function is called for vtables must
809 remain the same, otherwise binary compatibility can be
814 char *buf1 = (char *) alloca (TYPE_ASSEMBLER_NAME_LENGTH (for_type)
818 sprintf (buf1, "%s%c%s", TYPE_ASSEMBLER_NAME_STRING (for_type), joiner,
820 buf = (char *) alloca (strlen (VTABLE_NAME_PREFIX) + strlen (buf1) + 1);
821 sprintf (buf, "%s%s", VTABLE_NAME_PREFIX, buf1);
822 name = get_identifier (buf);
824 /* If this name doesn't clash, then we can use it, otherwise
825 we add more to the name until it is unique. */
827 if (! IDENTIFIER_GLOBAL_VALUE (name))
830 /* Set values for next loop through, if the name isn't unique. */
832 path = BINFO_INHERITANCE_CHAIN (path);
834 /* We better not run out of stuff to make it unique. */
835 my_friendly_assert (path != NULL_TREE, 368);
837 basetype = TYPE_MAIN_VARIANT (BINFO_TYPE (path));
839 if (for_type == basetype)
841 /* If we run out of basetypes in the path, we have already
842 found created a vtable with that name before, we now
843 resort to tacking on _%d to distinguish them. */
845 i = TYPE_ASSEMBLER_NAME_LENGTH (basetype) + 1 + i + 1 + 3;
846 buf1 = (char *) alloca (i);
848 sprintf (buf1, "%s%c%s%c%d",
849 TYPE_ASSEMBLER_NAME_STRING (basetype), joiner,
851 buf = (char *) alloca (strlen (VTABLE_NAME_PREFIX)
852 + strlen (buf1) + 1);
853 sprintf (buf, "%s%s", VTABLE_NAME_PREFIX, buf1);
854 name = get_identifier (buf);
856 /* If this name doesn't clash, then we can use it,
857 otherwise we add something different to the name until
859 } while (++j <= 999 && IDENTIFIER_GLOBAL_VALUE (name));
861 /* Hey, they really like MI don't they? Increase the 3
862 above to 6, and the 999 to 999999. :-) */
863 my_friendly_assert (j <= 999, 369);
868 i = TYPE_ASSEMBLER_NAME_LENGTH (basetype) + 1 + i;
869 new_buf2 = (char *) alloca (i);
870 sprintf (new_buf2, "%s%c%s",
871 TYPE_ASSEMBLER_NAME_STRING (basetype), joiner, buf2);
875 new_decl = build_lang_decl (VAR_DECL, name, TREE_TYPE (orig_decl));
876 /* Remember which class this vtable is really for. */
877 DECL_CONTEXT (new_decl) = for_type;
879 DECL_ARTIFICIAL (new_decl) = 1;
880 TREE_STATIC (new_decl) = 1;
881 BINFO_VTABLE (binfo) = pushdecl_top_level (new_decl);
882 DECL_VIRTUAL_P (new_decl) = 1;
883 #ifndef WRITABLE_VTABLES
884 /* Make them READONLY by default. (mrs) */
885 TREE_READONLY (new_decl) = 1;
887 DECL_ALIGN (new_decl) = DECL_ALIGN (orig_decl);
889 /* Make fresh virtual list, so we can smash it later. */
890 BINFO_VIRTUALS (binfo) = copy_list (BINFO_VIRTUALS (binfo));
892 if (TREE_VIA_VIRTUAL (binfo))
894 tree binfo1 = BINFO_FOR_VBASE (BINFO_TYPE (binfo), for_type);
896 /* XXX - This should never happen, if it does, the caller should
897 ensure that the binfo is from for_type's binfos, not from any
898 base type's. We can remove all this code after a while. */
900 warning ("internal inconsistency: binfo offset error for rtti");
902 offset = BINFO_OFFSET (binfo1);
905 offset = BINFO_OFFSET (binfo);
907 set_rtti_entry (BINFO_VIRTUALS (binfo),
908 ssize_binop (MINUS_EXPR, integer_zero_node, offset),
911 #ifdef GATHER_STATISTICS
913 n_vtable_elems += list_length (BINFO_VIRTUALS (binfo));
916 /* Set TREE_PUBLIC and TREE_EXTERN as appropriate. */
917 import_export_vtable (new_decl, for_type, 0);
919 if (TREE_VIA_VIRTUAL (binfo))
920 my_friendly_assert (binfo == BINFO_FOR_VBASE (BINFO_TYPE (binfo),
923 SET_BINFO_NEW_VTABLE_MARKED (binfo);
926 /* Change the offset for the FNDECL entry to NEW_OFFSET. Also update
927 DECL_VINDEX (FNDECL). */
930 modify_vtable_entry (old_entry_in_list, new_offset, fndecl)
931 tree old_entry_in_list, new_offset, fndecl;
933 tree base_fndecl = TREE_VALUE (old_entry_in_list);
935 /* Update the entry. */
936 TREE_PURPOSE (old_entry_in_list) = new_offset;
937 TREE_VALUE (old_entry_in_list) = fndecl;
939 /* Now assign virtual dispatch information, if unset. We can
940 dispatch this, through any overridden base function. */
941 if (TREE_CODE (DECL_VINDEX (fndecl)) != INTEGER_CST)
943 DECL_VINDEX (fndecl) = DECL_VINDEX (base_fndecl);
944 DECL_CONTEXT (fndecl) = DECL_CONTEXT (base_fndecl);
948 /* Access the virtual function table entry N. VIRTUALS is the virtual
949 function table's initializer. */
952 get_vtable_entry_n (virtuals, n)
954 unsigned HOST_WIDE_INT n;
959 virtuals = TREE_CHAIN (virtuals);
964 /* Add a virtual function to all the appropriate vtables for the class
965 T. DECL_VINDEX(X) should be error_mark_node, if we want to
966 allocate a new slot in our table. If it is error_mark_node, we
967 know that no other function from another vtable is overridden by X.
968 HAS_VIRTUAL keeps track of how many virtuals there are in our main
969 vtable for the type, and we build upon the PENDING_VIRTUALS list
973 add_virtual_function (pv, phv, has_virtual, fndecl, t)
977 tree t; /* Structure type. */
979 tree pending_virtuals = *pv;
980 tree pending_hard_virtuals = *phv;
983 if (current_class_type == 0)
984 cp_warning ("internal problem, current_class_type is zero when adding `%D', please report",
986 if (current_class_type && t != current_class_type)
987 cp_warning ("internal problem, current_class_type differs when adding `%D', please report",
991 /* If the virtual function is a redefinition of a prior one,
992 figure out in which base class the new definition goes,
993 and if necessary, make a fresh virtual function table
994 to hold that entry. */
995 if (DECL_VINDEX (fndecl) == error_mark_node)
997 /* We remember that this was the base sub-object for rtti. */
998 CLASSTYPE_RTTI (t) = t;
1000 /* If we are using thunks, use two slots at the front, one
1001 for the offset pointer, one for the tdesc pointer.
1002 For ARM-style vtables, use the same slot for both. */
1003 if (*has_virtual == 0 && ! CLASSTYPE_COM_INTERFACE (t))
1005 if (flag_vtable_thunks)
1011 /* Build a new INT_CST for this DECL_VINDEX. */
1013 static tree index_table[256];
1015 /* We skip a slot for the offset/tdesc entry. */
1016 int i = (*has_virtual)++;
1018 if (i >= 256 || index_table[i] == 0)
1020 idx = build_int_2 (i, 0);
1022 index_table[i] = idx;
1025 idx = index_table[i];
1027 /* Now assign virtual dispatch information. */
1028 DECL_VINDEX (fndecl) = idx;
1029 DECL_CONTEXT (fndecl) = t;
1031 /* Save the state we've computed on the PENDING_VIRTUALS list. */
1032 pending_virtuals = tree_cons (integer_zero_node,
1036 /* Might already be INTEGER_CST if declared twice in class. We will
1037 give error later or we've already given it. */
1038 else if (TREE_CODE (DECL_VINDEX (fndecl)) != INTEGER_CST)
1040 /* Need an entry in some other virtual function table.
1041 Deal with this after we have laid out our virtual base classes. */
1042 pending_hard_virtuals = tree_cons (NULL_TREE,
1044 pending_hard_virtuals);
1046 *pv = pending_virtuals;
1047 *phv = pending_hard_virtuals;
1050 extern struct obstack *current_obstack;
1052 /* Add method METHOD to class TYPE.
1054 If non-NULL, FIELDS is the entry in the METHOD_VEC vector entry of
1055 the class type where the method should be added. */
1058 add_method (type, fields, method)
1059 tree type, *fields, method;
1061 /* Setting the DECL_CONTEXT and DECL_CLASS_CONTEXT here is probably
1063 DECL_CONTEXT (method) = type;
1064 DECL_CLASS_CONTEXT (method) = type;
1066 if (fields && *fields)
1067 *fields = build_overload (method, *fields);
1074 if (!CLASSTYPE_METHOD_VEC (type))
1075 /* Make a new method vector. We start with 8 entries. We must
1076 allocate at least two (for constructors and destructors), and
1077 we're going to end up with an assignment operator at some
1080 We could use a TREE_LIST for now, and convert it to a
1081 TREE_VEC in finish_struct, but we would probably waste more
1082 memory making the links in the list than we would by
1083 over-allocating the size of the vector here. Furthermore,
1084 we would complicate all the code that expects this to be a
1086 CLASSTYPE_METHOD_VEC (type) = make_tree_vec (8);
1088 method_vec = CLASSTYPE_METHOD_VEC (type);
1089 len = TREE_VEC_LENGTH (method_vec);
1091 if (DECL_NAME (method) == constructor_name (type))
1092 /* A new constructor or destructor. Constructors go in
1093 slot 0; destructors go in slot 1. */
1094 slot = DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (method)) ? 1 : 0;
1097 /* See if we already have an entry with this name. */
1098 for (slot = 2; slot < len; ++slot)
1099 if (!TREE_VEC_ELT (method_vec, slot)
1100 || (DECL_NAME (OVL_CURRENT (TREE_VEC_ELT (method_vec,
1102 == DECL_NAME (method)))
1107 /* We need a bigger method vector. */
1108 tree new_vec = make_tree_vec (2 * len);
1109 bcopy ((PTR) &TREE_VEC_ELT (method_vec, 0),
1110 (PTR) &TREE_VEC_ELT (new_vec, 0),
1111 len * sizeof (tree));
1113 method_vec = CLASSTYPE_METHOD_VEC (type) = new_vec;
1116 if (DECL_CONV_FN_P (method) && !TREE_VEC_ELT (method_vec, slot))
1118 /* Type conversion operators have to come before
1119 ordinary methods; add_conversions depends on this to
1120 speed up looking for conversion operators. So, if
1121 necessary, we slide some of the vector elements up.
1122 In theory, this makes this algorithm O(N^2) but we
1123 don't expect many conversion operators. */
1124 for (slot = 2; slot < len; ++slot)
1126 tree fn = TREE_VEC_ELT (method_vec, slot);
1129 /* There are no more entries in the vector, so we
1130 can insert the new conversion operator here. */
1133 if (!DECL_CONV_FN_P (OVL_CURRENT (fn)))
1134 /* We can insert the new function right at the
1139 if (!TREE_VEC_ELT (method_vec, slot))
1140 /* There is nothing in the Ith slot, so we can avoid
1145 /* We know the last slot in the vector is empty
1146 because we know that at this point there's room
1147 for a new function. */
1148 bcopy ((PTR) &TREE_VEC_ELT (method_vec, slot),
1149 (PTR) &TREE_VEC_ELT (method_vec, slot + 1),
1150 (len - slot - 1) * sizeof (tree));
1151 TREE_VEC_ELT (method_vec, slot) = NULL_TREE;
1156 if (template_class_depth (type))
1157 /* TYPE is a template class. Don't issue any errors now; wait
1158 until instantiation time to complain. */
1164 /* Check to see if we've already got this method. */
1165 for (fns = TREE_VEC_ELT (method_vec, slot);
1167 fns = OVL_NEXT (fns))
1169 tree fn = OVL_CURRENT (fns);
1171 if (TREE_CODE (fn) != TREE_CODE (method))
1174 if (TREE_CODE (method) != TEMPLATE_DECL)
1176 /* [over.load] Member function declarations with the
1177 same name and the same parameter types cannot be
1178 overloaded if any of them is a static member
1179 function declaration. */
1180 if (DECL_STATIC_FUNCTION_P (fn)
1181 != DECL_STATIC_FUNCTION_P (method))
1183 tree parms1 = TYPE_ARG_TYPES (TREE_TYPE (fn));
1184 tree parms2 = TYPE_ARG_TYPES (TREE_TYPE (method));
1186 if (! DECL_STATIC_FUNCTION_P (fn))
1187 parms1 = TREE_CHAIN (parms1);
1189 parms2 = TREE_CHAIN (parms2);
1191 if (compparms (parms1, parms2))
1192 cp_error ("`%#D' and `%#D' cannot be overloaded",
1196 /* Since this is an ordinary function in a
1197 non-template class, it's mangled name can be used
1198 as a unique identifier. This technique is only
1199 an optimization; we would get the same results if
1200 we just used decls_match here. */
1201 if (DECL_ASSEMBLER_NAME (fn)
1202 != DECL_ASSEMBLER_NAME (method))
1205 else if (!decls_match (fn, method))
1208 /* There has already been a declaration of this method
1209 or member template. */
1210 cp_error_at ("`%D' has already been declared in `%T'",
1213 /* We don't call duplicate_decls here to merge the
1214 declarations because that will confuse things if the
1215 methods have inline definitions. In particular, we
1216 will crash while processing the definitions. */
1221 /* Actually insert the new method. */
1222 TREE_VEC_ELT (method_vec, slot)
1223 = build_overload (method, TREE_VEC_ELT (method_vec, slot));
1225 /* Add the new binding. */
1226 if (!DECL_CONSTRUCTOR_P (method)
1227 && !DECL_DESTRUCTOR_P (method))
1228 push_class_level_binding (DECL_NAME (method),
1229 TREE_VEC_ELT (method_vec, slot));
1233 /* Subroutines of finish_struct. */
1235 /* Look through the list of fields for this struct, deleting
1236 duplicates as we go. This must be recursive to handle
1239 FIELD is the field which may not appear anywhere in FIELDS.
1240 FIELD_PTR, if non-null, is the starting point at which
1241 chained deletions may take place.
1242 The value returned is the first acceptable entry found
1245 Note that anonymous fields which are not of UNION_TYPE are
1246 not duplicates, they are just anonymous fields. This happens
1247 when we have unnamed bitfields, for example. */
1250 delete_duplicate_fields_1 (field, fields)
1255 if (DECL_NAME (field) == 0)
1257 if (! ANON_AGGR_TYPE_P (TREE_TYPE (field)))
1260 for (x = TYPE_FIELDS (TREE_TYPE (field)); x; x = TREE_CHAIN (x))
1261 fields = delete_duplicate_fields_1 (x, fields);
1266 for (x = fields; x; prev = x, x = TREE_CHAIN (x))
1268 if (DECL_NAME (x) == 0)
1270 if (! ANON_AGGR_TYPE_P (TREE_TYPE (x)))
1272 TYPE_FIELDS (TREE_TYPE (x))
1273 = delete_duplicate_fields_1 (field, TYPE_FIELDS (TREE_TYPE (x)));
1274 if (TYPE_FIELDS (TREE_TYPE (x)) == 0)
1277 fields = TREE_CHAIN (fields);
1279 TREE_CHAIN (prev) = TREE_CHAIN (x);
1282 else if (TREE_CODE (field) == USING_DECL)
1283 /* A using declaration may is allowed to appear more than
1284 once. We'll prune these from the field list later, and
1285 handle_using_decl will complain about invalid multiple
1288 else if (DECL_NAME (field) == DECL_NAME (x))
1290 if (TREE_CODE (field) == CONST_DECL
1291 && TREE_CODE (x) == CONST_DECL)
1292 cp_error_at ("duplicate enum value `%D'", x);
1293 else if (TREE_CODE (field) == CONST_DECL
1294 || TREE_CODE (x) == CONST_DECL)
1295 cp_error_at ("duplicate field `%D' (as enum and non-enum)",
1297 else if (DECL_DECLARES_TYPE_P (field)
1298 && DECL_DECLARES_TYPE_P (x))
1300 if (same_type_p (TREE_TYPE (field), TREE_TYPE (x)))
1302 cp_error_at ("duplicate nested type `%D'", x);
1304 else if (DECL_DECLARES_TYPE_P (field)
1305 || DECL_DECLARES_TYPE_P (x))
1307 /* Hide tag decls. */
1308 if ((TREE_CODE (field) == TYPE_DECL
1309 && DECL_ARTIFICIAL (field))
1310 || (TREE_CODE (x) == TYPE_DECL
1311 && DECL_ARTIFICIAL (x)))
1313 cp_error_at ("duplicate field `%D' (as type and non-type)",
1317 cp_error_at ("duplicate member `%D'", x);
1319 fields = TREE_CHAIN (fields);
1321 TREE_CHAIN (prev) = TREE_CHAIN (x);
1329 delete_duplicate_fields (fields)
1333 for (x = fields; x && TREE_CHAIN (x); x = TREE_CHAIN (x))
1334 TREE_CHAIN (x) = delete_duplicate_fields_1 (x, TREE_CHAIN (x));
1337 /* Change the access of FDECL to ACCESS in T. The access to FDECL is
1338 along the path given by BINFO. Return 1 if change was legit,
1339 otherwise return 0. */
1342 alter_access (t, binfo, fdecl, access)
1348 tree elem = purpose_member (t, DECL_ACCESS (fdecl));
1351 if (TREE_VALUE (elem) != access)
1353 if (TREE_CODE (TREE_TYPE (fdecl)) == FUNCTION_DECL)
1354 cp_error_at ("conflicting access specifications for method `%D', ignored", TREE_TYPE (fdecl));
1356 error ("conflicting access specifications for field `%s', ignored",
1357 IDENTIFIER_POINTER (DECL_NAME (fdecl)));
1361 /* They're changing the access to the same thing they changed
1362 it to before. That's OK. */
1368 enforce_access (binfo, fdecl);
1369 DECL_ACCESS (fdecl) = tree_cons (t, access, DECL_ACCESS (fdecl));
1375 /* Process the USING_DECL, which is a member of T. */
1378 handle_using_decl (using_decl, t)
1382 tree ctype = DECL_INITIAL (using_decl);
1383 tree name = DECL_NAME (using_decl);
1385 = TREE_PRIVATE (using_decl) ? access_private_node
1386 : TREE_PROTECTED (using_decl) ? access_protected_node
1387 : access_public_node;
1389 tree flist = NULL_TREE;
1390 tree fields = TYPE_FIELDS (t);
1391 tree method_vec = CLASSTYPE_METHOD_VEC (t);
1396 binfo = binfo_or_else (ctype, t);
1400 if (name == constructor_name (ctype)
1401 || name == constructor_name_full (ctype))
1403 cp_error_at ("using-declaration for constructor", using_decl);
1407 fdecl = lookup_member (binfo, name, 0, 0);
1411 cp_error_at ("no members matching `%D' in `%#T'", using_decl, ctype);
1415 /* Functions are represented as TREE_LIST, with the purpose
1416 being the type and the value the functions. Other members
1417 come as themselves. */
1418 if (TREE_CODE (fdecl) == TREE_LIST)
1419 /* Ignore base type this came from. */
1420 fdecl = TREE_VALUE (fdecl);
1422 if (TREE_CODE (fdecl) == OVERLOAD)
1424 /* We later iterate over all functions. */
1426 fdecl = OVL_FUNCTION (flist);
1429 name = DECL_NAME (fdecl);
1430 n_methods = method_vec ? TREE_VEC_LENGTH (method_vec) : 0;
1431 for (i = 2; i < n_methods && TREE_VEC_ELT (method_vec, i); i++)
1432 if (DECL_NAME (OVL_CURRENT (TREE_VEC_ELT (method_vec, i)))
1435 cp_error ("cannot adjust access to `%#D' in `%#T'", fdecl, t);
1436 cp_error_at (" because of local method `%#D' with same name",
1437 OVL_CURRENT (TREE_VEC_ELT (method_vec, i)));
1441 if (! DECL_LANG_SPECIFIC (fdecl))
1442 /* We don't currently handle DECL_ACCESS for TYPE_DECLs; just return. */
1445 for (tmp = fields; tmp; tmp = TREE_CHAIN (tmp))
1446 if (DECL_NAME (tmp) == name)
1448 cp_error ("cannot adjust access to `%#D' in `%#T'", fdecl, t);
1449 cp_error_at (" because of local field `%#D' with same name", tmp);
1453 /* Make type T see field decl FDECL with access ACCESS.*/
1458 if (alter_access (t, binfo, OVL_FUNCTION (flist),
1461 flist = OVL_CHAIN (flist);
1465 alter_access (t, binfo, fdecl, access);
1468 /* Run through the base clases of T, updating
1469 CANT_HAVE_DEFAULT_CTOR_P, CANT_HAVE_CONST_CTOR_P, and
1470 NO_CONST_ASN_REF_P. Also set flag bits in T based on properties of
1474 check_bases (t, cant_have_default_ctor_p, cant_have_const_ctor_p,
1477 int *cant_have_default_ctor_p;
1478 int *cant_have_const_ctor_p;
1479 int *no_const_asn_ref_p;
1483 int seen_nearly_empty_base_p;
1486 binfos = TYPE_BINFO_BASETYPES (t);
1487 n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
1488 seen_nearly_empty_base_p = 0;
1490 /* An aggregate cannot have baseclasses. */
1491 CLASSTYPE_NON_AGGREGATE (t) |= (n_baseclasses != 0);
1493 for (i = 0; i < n_baseclasses; ++i)
1498 /* Figure out what base we're looking at. */
1499 base_binfo = TREE_VEC_ELT (binfos, i);
1500 basetype = TREE_TYPE (base_binfo);
1502 /* If the type of basetype is incomplete, then we already
1503 complained about that fact (and we should have fixed it up as
1505 if (TYPE_SIZE (basetype) == 0)
1508 /* The base type is of incomplete type. It is
1509 probably best to pretend that it does not
1511 if (i == n_baseclasses-1)
1512 TREE_VEC_ELT (binfos, i) = NULL_TREE;
1513 TREE_VEC_LENGTH (binfos) -= 1;
1515 for (j = i; j+1 < n_baseclasses; j++)
1516 TREE_VEC_ELT (binfos, j) = TREE_VEC_ELT (binfos, j+1);
1520 /* Effective C++ rule 14. We only need to check TYPE_POLYMORPHIC_P
1521 here because the case of virtual functions but non-virtual
1522 dtor is handled in finish_struct_1. */
1523 if (warn_ecpp && ! TYPE_POLYMORPHIC_P (basetype)
1524 && TYPE_HAS_DESTRUCTOR (basetype))
1525 cp_warning ("base class `%#T' has a non-virtual destructor",
1528 /* If the base class doesn't have copy constructors or
1529 assignment operators that take const references, then the
1530 derived class cannot have such a member automatically
1532 if (! TYPE_HAS_CONST_INIT_REF (basetype))
1533 *cant_have_const_ctor_p = 1;
1534 if (TYPE_HAS_ASSIGN_REF (basetype)
1535 && !TYPE_HAS_CONST_ASSIGN_REF (basetype))
1536 *no_const_asn_ref_p = 1;
1537 /* Similarly, if the base class doesn't have a default
1538 constructor, then the derived class won't have an
1539 automatically generated default constructor. */
1540 if (TYPE_HAS_CONSTRUCTOR (basetype)
1541 && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype))
1543 *cant_have_default_ctor_p = 1;
1544 if (! TYPE_HAS_CONSTRUCTOR (t))
1546 cp_pedwarn ("base `%T' with only non-default constructor",
1548 cp_pedwarn ("in class without a constructor");
1552 /* If the base class is not empty or nearly empty, then this
1553 class cannot be nearly empty. */
1554 if (!CLASSTYPE_NEARLY_EMPTY_P (basetype) && !is_empty_class (basetype))
1555 CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
1556 /* And if there is more than one nearly empty base, then the
1557 derived class is not nearly empty either. */
1558 else if (CLASSTYPE_NEARLY_EMPTY_P (basetype)
1559 && seen_nearly_empty_base_p)
1560 CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
1561 /* If this is the first nearly empty base class, then remember
1563 else if (CLASSTYPE_NEARLY_EMPTY_P (basetype))
1564 seen_nearly_empty_base_p = 1;
1566 /* A lot of properties from the bases also apply to the derived
1568 TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (basetype);
1569 TYPE_NEEDS_DESTRUCTOR (t) |= TYPE_NEEDS_DESTRUCTOR (basetype);
1570 TYPE_HAS_COMPLEX_ASSIGN_REF (t)
1571 |= TYPE_HAS_COMPLEX_ASSIGN_REF (basetype);
1572 TYPE_HAS_COMPLEX_INIT_REF (t) |= TYPE_HAS_COMPLEX_INIT_REF (basetype);
1573 TYPE_OVERLOADS_CALL_EXPR (t) |= TYPE_OVERLOADS_CALL_EXPR (basetype);
1574 TYPE_OVERLOADS_ARRAY_REF (t) |= TYPE_OVERLOADS_ARRAY_REF (basetype);
1575 TYPE_OVERLOADS_ARROW (t) |= TYPE_OVERLOADS_ARROW (basetype);
1576 TYPE_POLYMORPHIC_P (t) |= TYPE_POLYMORPHIC_P (basetype);
1578 /* Derived classes can implicitly become COMified if their bases
1580 if (CLASSTYPE_COM_INTERFACE (basetype))
1581 CLASSTYPE_COM_INTERFACE (t) = 1;
1582 else if (i == 0 && CLASSTYPE_COM_INTERFACE (t))
1585 ("COM interface type `%T' with non-COM leftmost base class `%T'",
1587 CLASSTYPE_COM_INTERFACE (t) = 0;
1592 /* Make the Ith baseclass of T its primary base. */
1595 set_primary_base (t, i, has_virtual_p)
1602 CLASSTYPE_VFIELD_PARENT (t) = i;
1603 basetype = BINFO_TYPE (CLASSTYPE_PRIMARY_BINFO (t));
1604 TYPE_BINFO_VTABLE (t) = TYPE_BINFO_VTABLE (basetype);
1605 TYPE_BINFO_VIRTUALS (t) = TYPE_BINFO_VIRTUALS (basetype);
1606 TYPE_VFIELD (t) = TYPE_VFIELD (basetype);
1607 CLASSTYPE_RTTI (t) = CLASSTYPE_RTTI (basetype);
1608 *has_virtual_p = CLASSTYPE_VSIZE (basetype);
1611 /* Determine the primary class for T. */
1614 determine_primary_base (t, has_virtual_p)
1618 int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
1620 /* If there are no baseclasses, there is certainly no primary base. */
1621 if (n_baseclasses == 0)
1626 for (i = 0; i < n_baseclasses; i++)
1628 tree base_binfo = TREE_VEC_ELT (TYPE_BINFO_BASETYPES (t), i);
1629 tree basetype = BINFO_TYPE (base_binfo);
1631 if (TYPE_POLYMORPHIC_P (basetype))
1633 /* Even a virtual baseclass can contain our RTTI
1634 information. But, we prefer a non-virtual polymorphic
1636 if (!CLASSTYPE_HAS_PRIMARY_BASE_P (t))
1637 CLASSTYPE_RTTI (t) = CLASSTYPE_RTTI (basetype);
1639 /* A virtual baseclass can't be the primary base under the
1640 old ABI. And under the new ABI we still prefer a
1641 non-virtual base. */
1642 if (TREE_VIA_VIRTUAL (base_binfo))
1645 if (!CLASSTYPE_HAS_PRIMARY_BASE_P (t))
1647 set_primary_base (t, i, has_virtual_p);
1648 CLASSTYPE_VFIELDS (t) = copy_list (CLASSTYPE_VFIELDS (basetype));
1654 /* Only add unique vfields, and flatten them out as we go. */
1655 for (vfields = CLASSTYPE_VFIELDS (basetype);
1657 vfields = TREE_CHAIN (vfields))
1658 if (VF_BINFO_VALUE (vfields) == NULL_TREE
1659 || ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields)))
1660 CLASSTYPE_VFIELDS (t)
1661 = tree_cons (base_binfo,
1662 VF_BASETYPE_VALUE (vfields),
1663 CLASSTYPE_VFIELDS (t));
1665 if (*has_virtual_p == 0)
1666 set_primary_base (t, i, has_virtual_p);
1671 if (!TYPE_VFIELD (t))
1672 CLASSTYPE_VFIELD_PARENT (t) = -1;
1674 /* The new ABI allows for the use of a "nearly-empty" virtual base
1675 class as the primary base class if no non-virtual polymorphic
1676 base can be found. */
1677 if (flag_new_abi && !CLASSTYPE_HAS_PRIMARY_BASE_P (t))
1678 for (i = 0; i < n_baseclasses; ++i)
1680 tree base_binfo = TREE_VEC_ELT (TYPE_BINFO_BASETYPES (t), i);
1681 tree basetype = BINFO_TYPE (base_binfo);
1683 if (TREE_VIA_VIRTUAL (base_binfo)
1684 && CLASSTYPE_NEARLY_EMPTY_P (basetype))
1686 set_primary_base (t, i, has_virtual_p);
1687 CLASSTYPE_VFIELDS (t) = copy_list (CLASSTYPE_VFIELDS (basetype));
1692 /* Mark the primary base classes at this point. */
1693 mark_primary_bases (t);
1696 /* Set memoizing fields and bits of T (and its variants) for later
1700 finish_struct_bits (t)
1703 int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
1705 /* Fix up variants (if any). */
1706 tree variants = TYPE_NEXT_VARIANT (t);
1709 /* These fields are in the _TYPE part of the node, not in
1710 the TYPE_LANG_SPECIFIC component, so they are not shared. */
1711 TYPE_HAS_CONSTRUCTOR (variants) = TYPE_HAS_CONSTRUCTOR (t);
1712 TYPE_HAS_DESTRUCTOR (variants) = TYPE_HAS_DESTRUCTOR (t);
1713 TYPE_NEEDS_CONSTRUCTING (variants) = TYPE_NEEDS_CONSTRUCTING (t);
1714 TYPE_NEEDS_DESTRUCTOR (variants) = TYPE_NEEDS_DESTRUCTOR (t);
1716 TYPE_BASE_CONVS_MAY_REQUIRE_CODE_P (variants)
1717 = TYPE_BASE_CONVS_MAY_REQUIRE_CODE_P (t);
1718 TYPE_POLYMORPHIC_P (variants) = TYPE_POLYMORPHIC_P (t);
1719 TYPE_USES_VIRTUAL_BASECLASSES (variants) = TYPE_USES_VIRTUAL_BASECLASSES (t);
1720 /* Copy whatever these are holding today. */
1721 TYPE_MIN_VALUE (variants) = TYPE_MIN_VALUE (t);
1722 TYPE_MAX_VALUE (variants) = TYPE_MAX_VALUE (t);
1723 TYPE_FIELDS (variants) = TYPE_FIELDS (t);
1724 TYPE_SIZE (variants) = TYPE_SIZE (t);
1725 TYPE_SIZE_UNIT (variants) = TYPE_SIZE_UNIT (t);
1726 variants = TYPE_NEXT_VARIANT (variants);
1729 if (n_baseclasses && TYPE_POLYMORPHIC_P (t))
1730 /* For a class w/o baseclasses, `finish_struct' has set
1731 CLASS_TYPE_ABSTRACT_VIRTUALS correctly (by
1732 definition). Similarly for a class whose base classes do not
1733 have vtables. When neither of these is true, we might have
1734 removed abstract virtuals (by providing a definition), added
1735 some (by declaring new ones), or redeclared ones from a base
1736 class. We need to recalculate what's really an abstract virtual
1737 at this point (by looking in the vtables). */
1738 get_pure_virtuals (t);
1742 /* Notice whether this class has type conversion functions defined. */
1743 tree binfo = TYPE_BINFO (t);
1744 tree binfos = BINFO_BASETYPES (binfo);
1747 for (i = n_baseclasses-1; i >= 0; i--)
1749 basetype = BINFO_TYPE (TREE_VEC_ELT (binfos, i));
1751 TYPE_HAS_CONVERSION (t) |= TYPE_HAS_CONVERSION (basetype);
1755 /* If this type has a copy constructor, force its mode to be BLKmode, and
1756 force its TREE_ADDRESSABLE bit to be nonzero. This will cause it to
1757 be passed by invisible reference and prevent it from being returned in
1760 Also do this if the class has BLKmode but can still be returned in
1761 registers, since function_cannot_inline_p won't let us inline
1762 functions returning such a type. This affects the HP-PA. */
1763 if (! TYPE_HAS_TRIVIAL_INIT_REF (t)
1764 || (TYPE_MODE (t) == BLKmode && ! aggregate_value_p (t)
1765 && CLASSTYPE_NON_AGGREGATE (t)))
1768 DECL_MODE (TYPE_MAIN_DECL (t)) = BLKmode;
1769 for (variants = t; variants; variants = TYPE_NEXT_VARIANT (variants))
1771 TYPE_MODE (variants) = BLKmode;
1772 TREE_ADDRESSABLE (variants) = 1;
1777 /* Issue warnings about T having private constructors, but no friends,
1780 HAS_NONPRIVATE_METHOD is nonzero if T has any non-private methods or
1781 static members. HAS_NONPRIVATE_STATIC_FN is nonzero if T has any
1782 non-private static member functions. */
1785 maybe_warn_about_overly_private_class (t)
1788 int has_member_fn = 0;
1789 int has_nonprivate_method = 0;
1792 if (!warn_ctor_dtor_privacy
1793 /* If the class has friends, those entities might create and
1794 access instances, so we should not warn. */
1795 || (CLASSTYPE_FRIEND_CLASSES (t)
1796 || DECL_FRIENDLIST (TYPE_MAIN_DECL (t)))
1797 /* We will have warned when the template was declared; there's
1798 no need to warn on every instantiation. */
1799 || CLASSTYPE_TEMPLATE_INSTANTIATION (t))
1800 /* There's no reason to even consider warning about this
1804 /* We only issue one warning, if more than one applies, because
1805 otherwise, on code like:
1808 // Oops - forgot `public:'
1814 we warn several times about essentially the same problem. */
1816 /* Check to see if all (non-constructor, non-destructor) member
1817 functions are private. (Since there are no friends or
1818 non-private statics, we can't ever call any of the private member
1820 for (fn = TYPE_METHODS (t); fn; fn = TREE_CHAIN (fn))
1821 /* We're not interested in compiler-generated methods; they don't
1822 provide any way to call private members. */
1823 if (!DECL_ARTIFICIAL (fn))
1825 if (!TREE_PRIVATE (fn))
1827 if (DECL_STATIC_FUNCTION_P (fn))
1828 /* A non-private static member function is just like a
1829 friend; it can create and invoke private member
1830 functions, and be accessed without a class
1834 has_nonprivate_method = 1;
1837 else if (!DECL_CONSTRUCTOR_P (fn) && !DECL_DESTRUCTOR_P (fn))
1841 if (!has_nonprivate_method && has_member_fn)
1843 /* There are no non-private methods, and there's at least one
1844 private member function that isn't a constructor or
1845 destructor. (If all the private members are
1846 constructors/destructors we want to use the code below that
1847 issues error messages specifically referring to
1848 constructors/destructors.) */
1850 tree binfos = BINFO_BASETYPES (TYPE_BINFO (t));
1851 for (i = 0; i < CLASSTYPE_N_BASECLASSES (t); i++)
1852 if (TREE_VIA_PUBLIC (TREE_VEC_ELT (binfos, i))
1853 || TREE_VIA_PROTECTED (TREE_VEC_ELT (binfos, i)))
1855 has_nonprivate_method = 1;
1858 if (!has_nonprivate_method)
1860 cp_warning ("all member functions in class `%T' are private", t);
1865 /* Even if some of the member functions are non-private, the class
1866 won't be useful for much if all the constructors or destructors
1867 are private: such an object can never be created or destroyed. */
1868 if (TYPE_HAS_DESTRUCTOR (t))
1870 tree dtor = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (t), 1);
1872 if (TREE_PRIVATE (dtor))
1874 cp_warning ("`%#T' only defines a private destructor and has no friends",
1880 if (TYPE_HAS_CONSTRUCTOR (t))
1882 int nonprivate_ctor = 0;
1884 /* If a non-template class does not define a copy
1885 constructor, one is defined for it, enabling it to avoid
1886 this warning. For a template class, this does not
1887 happen, and so we would normally get a warning on:
1889 template <class T> class C { private: C(); };
1891 To avoid this asymmetry, we check TYPE_HAS_INIT_REF. All
1892 complete non-template or fully instantiated classes have this
1894 if (!TYPE_HAS_INIT_REF (t))
1895 nonprivate_ctor = 1;
1897 for (fn = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (t), 0);
1901 tree ctor = OVL_CURRENT (fn);
1902 /* Ideally, we wouldn't count copy constructors (or, in
1903 fact, any constructor that takes an argument of the
1904 class type as a parameter) because such things cannot
1905 be used to construct an instance of the class unless
1906 you already have one. But, for now at least, we're
1908 if (! TREE_PRIVATE (ctor))
1910 nonprivate_ctor = 1;
1915 if (nonprivate_ctor == 0)
1917 cp_warning ("`%#T' only defines private constructors and has no friends",
1924 /* Function to help qsort sort FIELD_DECLs by name order. */
1927 field_decl_cmp (x, y)
1930 if (DECL_NAME (*x) == DECL_NAME (*y))
1931 /* A nontype is "greater" than a type. */
1932 return DECL_DECLARES_TYPE_P (*y) - DECL_DECLARES_TYPE_P (*x);
1933 if (DECL_NAME (*x) == NULL_TREE)
1935 if (DECL_NAME (*y) == NULL_TREE)
1937 if (DECL_NAME (*x) < DECL_NAME (*y))
1942 /* Comparison function to compare two TYPE_METHOD_VEC entries by name. */
1945 method_name_cmp (m1, m2)
1946 const tree *m1, *m2;
1948 if (*m1 == NULL_TREE && *m2 == NULL_TREE)
1950 if (*m1 == NULL_TREE)
1952 if (*m2 == NULL_TREE)
1954 if (DECL_NAME (OVL_CURRENT (*m1)) < DECL_NAME (OVL_CURRENT (*m2)))
1959 /* Warn about duplicate methods in fn_fields. Also compact method
1960 lists so that lookup can be made faster.
1962 Data Structure: List of method lists. The outer list is a
1963 TREE_LIST, whose TREE_PURPOSE field is the field name and the
1964 TREE_VALUE is the DECL_CHAIN of the FUNCTION_DECLs. TREE_CHAIN
1965 links the entire list of methods for TYPE_METHODS. Friends are
1966 chained in the same way as member functions (? TREE_CHAIN or
1967 DECL_CHAIN), but they live in the TREE_TYPE field of the outer
1968 list. That allows them to be quickly deleted, and requires no
1971 If there are any constructors/destructors, they are moved to the
1972 front of the list. This makes pushclass more efficient.
1974 @@ The above comment is obsolete. It mostly describes what add_method
1975 @@ and add_implicitly_declared_members do.
1977 Sort methods that are not special (i.e., constructors, destructors, and
1978 type conversion operators) so that we can find them faster in search. */
1981 finish_struct_methods (t)
1986 tree ctor_name = constructor_name (t);
1989 if (!TYPE_METHODS (t))
1991 /* Clear these for safety; perhaps some parsing error could set
1992 these incorrectly. */
1993 TYPE_HAS_CONSTRUCTOR (t) = 0;
1994 TYPE_HAS_DESTRUCTOR (t) = 0;
1995 CLASSTYPE_METHOD_VEC (t) = NULL_TREE;
1999 method_vec = CLASSTYPE_METHOD_VEC (t);
2000 my_friendly_assert (method_vec != NULL_TREE, 19991215);
2001 len = TREE_VEC_LENGTH (method_vec);
2003 /* First fill in entry 0 with the constructors, entry 1 with destructors,
2004 and the next few with type conversion operators (if any). */
2005 for (fn_fields = TYPE_METHODS (t); fn_fields;
2006 fn_fields = TREE_CHAIN (fn_fields))
2008 tree fn_name = DECL_NAME (fn_fields);
2010 /* Clear out this flag.
2012 @@ Doug may figure out how to break
2013 @@ this with nested classes and friends. */
2014 DECL_IN_AGGR_P (fn_fields) = 0;
2016 /* Note here that a copy ctor is private, so we don't dare generate
2017 a default copy constructor for a class that has a member
2018 of this type without making sure they have access to it. */
2019 if (fn_name == ctor_name)
2021 tree parmtypes = FUNCTION_ARG_CHAIN (fn_fields);
2022 tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node;
2024 if (TREE_CODE (parmtype) == REFERENCE_TYPE
2025 && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == t)
2027 if (TREE_CHAIN (parmtypes) == NULL_TREE
2028 || TREE_CHAIN (parmtypes) == void_list_node
2029 || TREE_PURPOSE (TREE_CHAIN (parmtypes)))
2031 if (TREE_PROTECTED (fn_fields))
2032 TYPE_HAS_NONPUBLIC_CTOR (t) = 1;
2033 else if (TREE_PRIVATE (fn_fields))
2034 TYPE_HAS_NONPUBLIC_CTOR (t) = 2;
2038 else if (fn_name == ansi_opname[(int) MODIFY_EXPR])
2040 tree parmtype = TREE_VALUE (FUNCTION_ARG_CHAIN (fn_fields));
2042 if (copy_assignment_arg_p (parmtype, DECL_VIRTUAL_P (fn_fields)))
2044 if (TREE_PROTECTED (fn_fields))
2045 TYPE_HAS_NONPUBLIC_ASSIGN_REF (t) = 1;
2046 else if (TREE_PRIVATE (fn_fields))
2047 TYPE_HAS_NONPUBLIC_ASSIGN_REF (t) = 2;
2052 if (TYPE_HAS_DESTRUCTOR (t) && !TREE_VEC_ELT (method_vec, 1))
2053 /* We thought there was a destructor, but there wasn't. Some
2054 parse errors cause this anomalous situation. */
2055 TYPE_HAS_DESTRUCTOR (t) = 0;
2057 /* Issue warnings about private constructors and such. If there are
2058 no methods, then some public defaults are generated. */
2059 maybe_warn_about_overly_private_class (t);
2061 /* Now sort the methods. */
2062 while (len > 2 && TREE_VEC_ELT (method_vec, len-1) == NULL_TREE)
2064 TREE_VEC_LENGTH (method_vec) = len;
2066 /* The type conversion ops have to live at the front of the vec, so we
2068 for (slot = 2; slot < len; ++slot)
2070 tree fn = TREE_VEC_ELT (method_vec, slot);
2072 if (!DECL_CONV_FN_P (OVL_CURRENT (fn)))
2076 qsort (&TREE_VEC_ELT (method_vec, slot), len-slot, sizeof (tree),
2077 (int (*)(const void *, const void *))method_name_cmp);
2080 /* Emit error when a duplicate definition of a type is seen. Patch up. */
2083 duplicate_tag_error (t)
2086 cp_error ("redefinition of `%#T'", t);
2087 cp_error_at ("previous definition here", t);
2089 /* Pretend we haven't defined this type. */
2091 /* All of the component_decl's were TREE_CHAINed together in the parser.
2092 finish_struct_methods walks these chains and assembles all methods with
2093 the same base name into DECL_CHAINs. Now we don't need the parser chains
2094 anymore, so we unravel them. */
2096 /* This used to be in finish_struct, but it turns out that the
2097 TREE_CHAIN is used by dbxout_type_methods and perhaps some other
2099 if (CLASSTYPE_METHOD_VEC (t))
2101 tree method_vec = CLASSTYPE_METHOD_VEC (t);
2102 int i, len = TREE_VEC_LENGTH (method_vec);
2103 for (i = 0; i < len; i++)
2105 tree unchain = TREE_VEC_ELT (method_vec, i);
2106 while (unchain != NULL_TREE)
2108 TREE_CHAIN (OVL_CURRENT (unchain)) = NULL_TREE;
2109 unchain = OVL_NEXT (unchain);
2114 if (TYPE_LANG_SPECIFIC (t))
2116 tree binfo = TYPE_BINFO (t);
2117 int interface_only = CLASSTYPE_INTERFACE_ONLY (t);
2118 int interface_unknown = CLASSTYPE_INTERFACE_UNKNOWN (t);
2119 tree template_info = CLASSTYPE_TEMPLATE_INFO (t);
2120 int use_template = CLASSTYPE_USE_TEMPLATE (t);
2122 bzero ((char *) TYPE_LANG_SPECIFIC (t), sizeof (struct lang_type));
2123 BINFO_BASETYPES(binfo) = NULL_TREE;
2125 TYPE_BINFO (t) = binfo;
2126 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
2127 SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, interface_unknown);
2128 TYPE_REDEFINED (t) = 1;
2129 CLASSTYPE_TEMPLATE_INFO (t) = template_info;
2130 CLASSTYPE_USE_TEMPLATE (t) = use_template;
2132 TYPE_SIZE (t) = NULL_TREE;
2133 TYPE_MODE (t) = VOIDmode;
2134 TYPE_FIELDS (t) = NULL_TREE;
2135 TYPE_METHODS (t) = NULL_TREE;
2136 TYPE_VFIELD (t) = NULL_TREE;
2137 TYPE_CONTEXT (t) = NULL_TREE;
2138 TYPE_NONCOPIED_PARTS (t) = NULL_TREE;
2141 /* Construct the initializer for BINFOs virtual function table. */
2144 build_vtbl_initializer (binfo)
2147 tree v = BINFO_VIRTUALS (binfo);
2148 tree inits = NULL_TREE;
2150 /* Process the RTTI stuff at the head of the list. If we're not
2151 using vtable thunks, then the RTTI entry is just an ordinary
2152 function, and we can process it just like the other virtual
2153 function entries. */
2154 if (!CLASSTYPE_COM_INTERFACE (BINFO_TYPE (binfo))
2155 && flag_vtable_thunks)
2160 /* The first entry is an offset. */
2161 offset = TREE_PURPOSE (v);
2162 my_friendly_assert (TREE_CODE (offset) == INTEGER_CST,
2165 /* Convert the offset to look like a function pointer, so that
2166 we can put it in the vtable. */
2167 init = build1 (NOP_EXPR, vfunc_ptr_type_node, offset);
2168 TREE_CONSTANT (init) = 1;
2169 init = build_vtable_entry (integer_zero_node, init);
2170 inits = tree_cons (NULL_TREE, init, inits);
2172 /* Even in this case, the second entry (the tdesc pointer) is
2173 just an ordinary function. */
2177 /* Go through all the ordinary virtual functions, building up
2185 /* Pull the offset for `this', and the function to call, out of
2187 delta = TREE_PURPOSE (v);
2188 fn = TREE_VALUE (v);
2189 my_friendly_assert (TREE_CODE (delta) == INTEGER_CST, 19990727);
2190 my_friendly_assert (TREE_CODE (fn) == FUNCTION_DECL, 19990727);
2192 /* You can't call an abstract virtual function; it's abstract.
2193 So, we replace these functions with __pure_virtual. */
2194 if (DECL_PURE_VIRTUAL_P (fn))
2197 /* Package up that information for the vtable. */
2198 init = build_vtable_entry_for_fn (delta, fn);
2199 /* And add it to the chain of initializers. */
2200 inits = tree_cons (NULL_TREE, init, inits);
2206 /* The initializers were built up in reverse order; straighten them
2208 inits = nreverse (inits);
2209 /* Package all the initializers up as an array initializer. */
2210 return build_nt (CONSTRUCTOR, NULL_TREE, inits);
2213 /* Called from finish_vtbls via dfs_walk. */
2216 dfs_finish_vtbls (binfo, data)
2218 void *data ATTRIBUTE_UNUSED;
2220 if (!BINFO_PRIMARY_MARKED_P (binfo)
2221 && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo))
2222 && BINFO_NEW_VTABLE_MARKED (binfo))
2227 decl = BINFO_VTABLE (binfo);
2228 context = DECL_CONTEXT (decl);
2229 DECL_CONTEXT (decl) = 0;
2230 DECL_INITIAL (decl) = build_vtbl_initializer (binfo);
2231 cp_finish_decl (decl, DECL_INITIAL (decl), NULL_TREE, 0);
2232 DECL_CONTEXT (decl) = context;
2235 CLEAR_BINFO_NEW_VTABLE_MARKED (binfo);
2236 SET_BINFO_MARKED (binfo);
2241 /* Create all the necessary vtables for T and its base classes. */
2247 dfs_walk (TYPE_BINFO (t), dfs_finish_vtbls,
2248 dfs_unmarked_real_bases_queue_p, t);
2249 dfs_walk (TYPE_BINFO (t), dfs_unmark,
2250 dfs_marked_real_bases_queue_p, t);
2253 /* True if we should override the given BASE_FNDECL with the given
2257 overrides (fndecl, base_fndecl)
2258 tree fndecl, base_fndecl;
2260 /* Destructors have special names. */
2261 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (base_fndecl))
2262 && DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
2264 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (base_fndecl))
2265 || DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
2267 if (DECL_NAME (fndecl) == DECL_NAME (base_fndecl))
2269 tree types, base_types;
2271 retypes = TREE_TYPE (TREE_TYPE (fndecl));
2272 base_retypes = TREE_TYPE (TREE_TYPE (base_fndecl));
2274 types = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
2275 base_types = TYPE_ARG_TYPES (TREE_TYPE (base_fndecl));
2276 if ((TYPE_QUALS (TREE_TYPE (TREE_VALUE (base_types)))
2277 == TYPE_QUALS (TREE_TYPE (TREE_VALUE (types))))
2278 && compparms (TREE_CHAIN (base_types), TREE_CHAIN (types)))
2284 /* Returns the BINFO_OFFSET for the base of BINFO that has the same
2288 get_class_offset_1 (parent, binfo, context, t, fndecl)
2289 tree parent, binfo, context, t, fndecl;
2291 tree binfos = BINFO_BASETYPES (binfo);
2292 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2293 tree rval = NULL_TREE;
2295 if (binfo == parent)
2296 return error_mark_node;
2298 for (i = 0; i < n_baselinks; i++)
2300 tree base_binfo = TREE_VEC_ELT (binfos, i);
2303 if (TREE_VIA_VIRTUAL (base_binfo))
2304 base_binfo = BINFO_FOR_VBASE (BINFO_TYPE (base_binfo), t);
2305 nrval = get_class_offset_1 (parent, base_binfo, context, t, fndecl);
2306 /* See if we have a new value */
2307 if (nrval && (nrval != error_mark_node || rval==0))
2309 /* Only compare if we have two offsets */
2310 if (rval && rval != error_mark_node
2311 && ! tree_int_cst_equal (nrval, rval))
2313 /* Only give error if the two offsets are different */
2314 error ("every virtual function must have a unique final overrider");
2315 cp_error (" found two (or more) `%T' class subobjects in `%T'", context, t);
2316 cp_error (" with virtual `%D' from virtual base class", fndecl);
2322 if (rval && BINFO_TYPE (binfo) == context)
2324 my_friendly_assert (rval == error_mark_node
2325 || tree_int_cst_equal (rval, BINFO_OFFSET (binfo)), 999);
2326 rval = BINFO_OFFSET (binfo);
2332 /* Called from get_class_offset via dfs_walk. */
2335 dfs_get_class_offset (binfo, data)
2339 tree list = (tree) data;
2340 tree context = TREE_TYPE (list);
2342 if (same_type_p (BINFO_TYPE (binfo), context))
2344 if (TREE_VALUE (list))
2345 return error_mark_node;
2347 TREE_VALUE (list) = BINFO_OFFSET (binfo);
2350 SET_BINFO_MARKED (binfo);
2355 /* Returns the BINFO_OFFSET for the subobject of BINFO that has the
2356 type given by CONTEXT. */
2359 get_class_offset (context, t, binfo, fndecl)
2360 tree context, t, binfo, fndecl;
2367 return integer_zero_node;
2369 if (BINFO_TYPE (binfo) == context)
2370 return BINFO_OFFSET (binfo);
2372 /* Check less derived binfos first. */
2373 while (BINFO_BASETYPES (binfo)
2374 && (i=CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo))) != -1)
2376 tree binfos = BINFO_BASETYPES (binfo);
2377 binfo = TREE_VEC_ELT (binfos, i);
2378 if (BINFO_TYPE (binfo) == context)
2379 return BINFO_OFFSET (binfo);
2382 list = build_tree_list (t, NULL_TREE);
2383 TREE_TYPE (list) = context;
2384 offset = dfs_walk (TYPE_BINFO (t),
2385 dfs_get_class_offset,
2386 dfs_unmarked_real_bases_queue_p,
2388 dfs_walk (TYPE_BINFO (t), dfs_unmark, dfs_marked_real_bases_queue_p, t);
2390 if (offset == error_mark_node)
2392 error ("every virtual function must have a unique final overrider");
2393 cp_error (" found two (or more) `%T' class subobjects in `%T'",
2395 cp_error (" with virtual `%D' from virtual base class", fndecl);
2396 offset = integer_zero_node;
2399 offset = TREE_VALUE (list);
2401 my_friendly_assert (offset != NULL_TREE, 999);
2402 my_friendly_assert (TREE_CODE (offset) == INTEGER_CST, 999);
2407 /* Return the BINFO_VIRTUALS list for BINFO, without the RTTI stuff at
2408 the front. If non-NULL, N is set to the number of entries
2412 skip_rtti_stuff (binfo, t, n)
2415 unsigned HOST_WIDE_INT *n;
2419 if (CLASSTYPE_COM_INTERFACE (t))
2424 virtuals = BINFO_VIRTUALS (binfo);
2427 /* We always reserve a slot for the offset/tdesc entry. */
2430 virtuals = TREE_CHAIN (virtuals);
2432 if (flag_vtable_thunks && virtuals)
2434 /* The second slot is reserved for the tdesc pointer when thunks
2438 virtuals = TREE_CHAIN (virtuals);
2445 modify_one_vtable (binfo, t, fndecl)
2446 tree binfo, t, fndecl;
2449 unsigned HOST_WIDE_INT n;
2451 /* update rtti entry */
2454 if (binfo == TYPE_BINFO (t))
2455 build_vtable (TYPE_BINFO (DECL_CONTEXT (TYPE_VFIELD (t))), t);
2457 prepare_fresh_vtable (binfo, t);
2459 if (fndecl == NULL_TREE)
2462 virtuals = skip_rtti_stuff (binfo, BINFO_TYPE (binfo), &n);
2466 tree current_fndecl = TREE_VALUE (virtuals);
2468 /* We should never have an instance of __pure_virtual on the
2469 BINFO_VIRTUALS list. If we do, then we will never notice
2470 that the function that should have been there instead has
2472 my_friendly_assert (current_fndecl != abort_fndecl,
2475 if (current_fndecl && overrides (fndecl, current_fndecl))
2477 tree base_offset, offset;
2478 tree context = DECL_CLASS_CONTEXT (fndecl);
2479 tree vfield = TYPE_VFIELD (t);
2482 offset = get_class_offset (context, t, binfo, fndecl);
2484 /* Find the right offset for the this pointer based on the
2485 base class we just found. We have to take into
2486 consideration the virtual base class pointers that we
2487 stick in before the virtual function table pointer.
2489 Also, we want just the delta between the most base class
2490 that we derived this vfield from and us. */
2491 base_offset = size_binop (PLUS_EXPR,
2492 get_derived_offset (binfo, DECL_CONTEXT (current_fndecl)),
2493 BINFO_OFFSET (binfo));
2494 this_offset = ssize_binop (MINUS_EXPR, offset, base_offset);
2496 if (binfo == TYPE_BINFO (t))
2497 /* In this case, it is *type*'s vtable we are modifying.
2498 We start with the approximation that it's vtable is
2499 that of the immediate base class. */
2500 build_vtable (TYPE_BINFO (DECL_CONTEXT (vfield)), t);
2502 /* This is our very own copy of `basetype' to play with.
2503 Later, we will fill in all the virtual functions that
2504 override the virtual functions in these base classes
2505 which are not defined by the current type. */
2506 prepare_fresh_vtable (binfo, t);
2509 cp_warning ("in %D", DECL_NAME (BINFO_VTABLE (binfo)));
2511 modify_vtable_entry (get_vtable_entry_n (BINFO_VIRTUALS (binfo), n),
2516 virtuals = TREE_CHAIN (virtuals);
2520 /* Called from modify_all_vtables via dfs_walk. */
2523 dfs_modify_vtables (binfo, data)
2527 if (/* There's no need to modify the vtable for a primary base;
2528 we're not going to use that vtable anyhow. */
2529 !BINFO_PRIMARY_MARKED_P (binfo)
2530 /* Similarly, a base without a vtable needs no modification. */
2531 && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2533 tree list = (tree) data;
2534 modify_one_vtable (binfo, TREE_PURPOSE (list), TREE_VALUE (list));
2537 SET_BINFO_MARKED (binfo);
2543 modify_all_vtables (t, fndecl)
2549 list = build_tree_list (t, fndecl);
2550 dfs_walk (TYPE_BINFO (t), dfs_modify_vtables,
2551 dfs_unmarked_real_bases_queue_p, list);
2552 dfs_walk (TYPE_BINFO (t), dfs_unmark, dfs_marked_real_bases_queue_p, t);
2555 /* Fixup all the delta entries in this one vtable that need updating. */
2558 dfs_fixup_vtable_deltas (binfo, data)
2563 unsigned HOST_WIDE_INT n;
2564 tree t = (tree) data;
2566 while (BINFO_PRIMARY_MARKED_P (binfo))
2568 binfo = BINFO_INHERITANCE_CHAIN (binfo);
2569 /* If BINFO is virtual then we'll handle this base later. */
2570 if (TREE_VIA_VIRTUAL (binfo))
2574 virtuals = skip_rtti_stuff (binfo, BINFO_TYPE (binfo), &n);
2578 tree fndecl = TREE_VALUE (virtuals);
2579 tree delta = TREE_PURPOSE (virtuals);
2583 tree base_offset, offset;
2584 tree context = DECL_CLASS_CONTEXT (fndecl);
2585 tree vfield = TYPE_VFIELD (t);
2588 offset = get_class_offset (context, t, binfo, fndecl);
2590 /* Find the right offset for the this pointer based on the
2591 base class we just found. We have to take into
2592 consideration the virtual base class pointers that we
2593 stick in before the virtual function table pointer.
2595 Also, we want just the delta between the most base class
2596 that we derived this vfield from and us. */
2597 base_offset = size_binop (PLUS_EXPR,
2598 get_derived_offset (binfo,
2599 DECL_CONTEXT (fndecl)),
2600 BINFO_OFFSET (binfo));
2601 this_offset = ssize_binop (MINUS_EXPR, offset, base_offset);
2603 if (! tree_int_cst_equal (this_offset, delta))
2605 /* Make sure we can modify the derived association with immunity. */
2606 if (binfo == TYPE_BINFO (t))
2607 /* In this case, it is *type*'s vtable we are modifying.
2608 We start with the approximation that it's vtable is that
2609 of the immediate base class. */
2610 build_vtable (TYPE_BINFO (DECL_CONTEXT (vfield)), t);
2612 /* This is our very own copy of `basetype' to play
2613 with. Later, we will fill in all the virtual
2614 functions that override the virtual functions in
2615 these base classes which are not defined by the
2617 prepare_fresh_vtable (binfo, t);
2619 modify_vtable_entry (get_vtable_entry_n (BINFO_VIRTUALS (binfo), n),
2625 virtuals = TREE_CHAIN (virtuals);
2631 /* Here, we already know that they match in every respect.
2632 All we have to check is where they had their declarations. */
2635 strictly_overrides (fndecl1, fndecl2)
2636 tree fndecl1, fndecl2;
2638 int distance = get_base_distance (DECL_CLASS_CONTEXT (fndecl2),
2639 DECL_CLASS_CONTEXT (fndecl1),
2641 if (distance == -2 || distance > 0)
2646 /* Merge overrides for one vtable.
2647 If we want to merge in same function, we are fine.
2649 if one has a DECL_CLASS_CONTEXT that is a parent of the
2650 other, than choose the more derived one
2652 potentially ill-formed (see 10.3 [class.virtual])
2653 we have to check later to see if there was an
2654 override in this class. If there was ok, if not
2655 then it is ill-formed. (mrs)
2657 We take special care to reuse a vtable, if we can. */
2660 override_one_vtable (binfo, old, t)
2667 enum { REUSE_NEW, REUSE_OLD, UNDECIDED, NEITHER } choose = UNDECIDED;
2669 /* Either or both of BINFO or OLD might be primary base classes
2670 because merge_overrides is called with a vbase from the class we
2671 are definining and the corresponding vbase from one of its direct
2674 while (BINFO_PRIMARY_MARKED_P (binfo))
2676 binfo = BINFO_INHERITANCE_CHAIN (binfo);
2677 /* If BINFO is virtual, then we'll handle this virtual base when
2679 if (TREE_VIA_VIRTUAL (binfo))
2682 while (BINFO_PRIMARY_MARKED_P (old))
2683 old = BINFO_INHERITANCE_CHAIN (old);
2685 /* If we have already committed to modifying it, then don't try and
2686 reuse another vtable. */
2687 if (BINFO_NEW_VTABLE_MARKED (binfo))
2690 virtuals = skip_rtti_stuff (binfo, BINFO_TYPE (binfo), NULL);
2691 old_virtuals = skip_rtti_stuff (old, BINFO_TYPE (binfo), NULL);
2692 orig_virtuals = skip_rtti_stuff (orig_binfo, BINFO_TYPE (binfo), NULL);
2694 while (orig_virtuals)
2696 tree fndecl = TREE_VALUE (virtuals);
2697 tree old_fndecl = TREE_VALUE (old_virtuals);
2699 /* First check to see if they are the same. */
2700 if (DECL_ASSEMBLER_NAME (fndecl) == DECL_ASSEMBLER_NAME (old_fndecl))
2702 /* No need to do anything. */
2704 else if (strictly_overrides (fndecl, old_fndecl))
2706 if (choose == UNDECIDED)
2708 else if (choose == REUSE_OLD)
2711 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2713 prepare_fresh_vtable (binfo, t);
2714 override_one_vtable (binfo, old, t);
2719 else if (strictly_overrides (old_fndecl, fndecl))
2721 if (choose == UNDECIDED)
2723 else if (choose == REUSE_NEW)
2726 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2728 prepare_fresh_vtable (binfo, t);
2729 override_one_vtable (binfo, old, t);
2732 TREE_VALUE (virtuals) = TREE_VALUE (old_virtuals);
2734 else if (choose == NEITHER)
2736 TREE_VALUE (virtuals) = TREE_VALUE (old_virtuals);
2742 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2744 prepare_fresh_vtable (binfo, t);
2745 override_one_vtable (binfo, old, t);
2749 /* This MUST be overridden, or the class is ill-formed. */
2750 tree fndecl = TREE_VALUE (virtuals);
2752 fndecl = copy_node (fndecl);
2753 copy_lang_decl (fndecl);
2754 DECL_NEEDS_FINAL_OVERRIDER_P (fndecl) = 1;
2755 /* Make sure we search for it later. */
2756 if (! CLASSTYPE_PURE_VIRTUALS (t))
2757 CLASSTYPE_PURE_VIRTUALS (t) = error_mark_node;
2759 /* We can use integer_zero_node, as we will core dump
2760 if this is used anyway. */
2761 TREE_PURPOSE (virtuals) = integer_zero_node;
2762 TREE_VALUE (virtuals) = fndecl;
2765 virtuals = TREE_CHAIN (virtuals);
2766 old_virtuals = TREE_CHAIN (old_virtuals);
2767 orig_virtuals = TREE_CHAIN (orig_virtuals);
2770 /* Let's reuse the old vtable. */
2771 if (choose == REUSE_OLD)
2773 BINFO_VTABLE (binfo) = BINFO_VTABLE (old);
2774 BINFO_VIRTUALS (binfo) = BINFO_VIRTUALS (old);
2778 /* Merge in overrides for virtual bases.
2779 BINFO is the hierarchy we want to modify, and OLD has the potential
2783 merge_overrides (binfo, old, do_self, t)
2788 tree binfos = BINFO_BASETYPES (binfo);
2789 tree old_binfos = BINFO_BASETYPES (old);
2790 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2792 /* Should we use something besides CLASSTYPE_VFIELDS? */
2793 if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2795 override_one_vtable (binfo, old, t);
2798 for (i = 0; i < n_baselinks; i++)
2800 tree base_binfo = TREE_VEC_ELT (binfos, i);
2801 tree old_base_binfo = TREE_VEC_ELT (old_binfos, i);
2802 int is_not_base_vtable
2803 = !BINFO_PRIMARY_MARKED_P (base_binfo);
2804 if (! TREE_VIA_VIRTUAL (base_binfo))
2805 merge_overrides (base_binfo, old_base_binfo, is_not_base_vtable, t);
2809 /* Get the base virtual function declarations in T that are either
2810 overridden or hidden by FNDECL as a list. We set TREE_PURPOSE with
2811 the overrider/hider. */
2814 get_basefndecls (fndecl, t)
2817 tree methods = TYPE_METHODS (t);
2818 tree base_fndecls = NULL_TREE;
2819 tree binfos = BINFO_BASETYPES (TYPE_BINFO (t));
2820 int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2824 if (TREE_CODE (methods) == FUNCTION_DECL
2825 && DECL_VINDEX (methods) != NULL_TREE
2826 && DECL_NAME (fndecl) == DECL_NAME (methods))
2827 base_fndecls = tree_cons (fndecl, methods, base_fndecls);
2829 methods = TREE_CHAIN (methods);
2833 return base_fndecls;
2835 for (i = 0; i < n_baseclasses; i++)
2837 tree base_binfo = TREE_VEC_ELT (binfos, i);
2838 tree basetype = BINFO_TYPE (base_binfo);
2840 base_fndecls = chainon (get_basefndecls (fndecl, basetype),
2844 return base_fndecls;
2847 /* Mark the functions that have been hidden with their overriders.
2848 Since we start out with all functions already marked with a hider,
2849 no need to mark functions that are just hidden.
2851 Subroutine of warn_hidden. */
2854 mark_overriders (fndecl, base_fndecls)
2855 tree fndecl, base_fndecls;
2857 for (; base_fndecls; base_fndecls = TREE_CHAIN (base_fndecls))
2859 if (overrides (fndecl, TREE_VALUE (base_fndecls)))
2860 TREE_PURPOSE (base_fndecls) = fndecl;
2864 /* If this declaration supersedes the declaration of
2865 a method declared virtual in the base class, then
2866 mark this field as being virtual as well. */
2869 check_for_override (decl, ctype)
2872 tree binfos = BINFO_BASETYPES (TYPE_BINFO (ctype));
2873 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2874 int virtualp = DECL_VIRTUAL_P (decl);
2875 int found_overriden_fn = 0;
2877 for (i = 0; i < n_baselinks; i++)
2879 tree base_binfo = TREE_VEC_ELT (binfos, i);
2880 if (TYPE_POLYMORPHIC_P (BINFO_TYPE (base_binfo)))
2882 tree tmp = get_matching_virtual
2884 DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl)));
2886 if (tmp && !found_overriden_fn)
2888 /* If this function overrides some virtual in some base
2889 class, then the function itself is also necessarily
2890 virtual, even if the user didn't explicitly say so. */
2891 DECL_VIRTUAL_P (decl) = 1;
2893 /* The TMP we really want is the one from the deepest
2894 baseclass on this path, taking care not to
2895 duplicate if we have already found it (via another
2896 path to its virtual baseclass. */
2897 if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE)
2899 cp_error_at ("`static %#D' cannot be declared", decl);
2900 cp_error_at (" since `virtual %#D' declared in base class",
2907 = tree_cons (NULL_TREE, tmp, DECL_VINDEX (decl));
2909 /* We now know that DECL overrides something,
2910 which is all that is important. But, we must
2911 continue to iterate through all the base-classes
2912 in order to allow get_matching_virtual to check for
2913 various illegal overrides. */
2914 found_overriden_fn = 1;
2920 if (DECL_VINDEX (decl) == NULL_TREE)
2921 DECL_VINDEX (decl) = error_mark_node;
2922 IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1;
2926 /* Warn about hidden virtual functions that are not overridden in t.
2927 We know that constructors and destructors don't apply. */
2933 tree method_vec = CLASSTYPE_METHOD_VEC (t);
2934 int n_methods = method_vec ? TREE_VEC_LENGTH (method_vec) : 0;
2937 /* We go through each separately named virtual function. */
2938 for (i = 2; i < n_methods && TREE_VEC_ELT (method_vec, i); ++i)
2940 tree fns = TREE_VEC_ELT (method_vec, i);
2941 tree fndecl = NULL_TREE;
2943 tree base_fndecls = NULL_TREE;
2944 tree binfos = BINFO_BASETYPES (TYPE_BINFO (t));
2945 int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2947 /* First see if we have any virtual functions in this batch. */
2948 for (; fns; fns = OVL_NEXT (fns))
2950 fndecl = OVL_CURRENT (fns);
2951 if (DECL_VINDEX (fndecl))
2955 if (fns == NULL_TREE)
2958 /* First we get a list of all possible functions that might be
2959 hidden from each base class. */
2960 for (i = 0; i < n_baseclasses; i++)
2962 tree base_binfo = TREE_VEC_ELT (binfos, i);
2963 tree basetype = BINFO_TYPE (base_binfo);
2965 base_fndecls = chainon (get_basefndecls (fndecl, basetype),
2969 fns = OVL_NEXT (fns);
2971 /* ...then mark up all the base functions with overriders, preferring
2972 overriders to hiders. */
2974 for (; fns; fns = OVL_NEXT (fns))
2976 fndecl = OVL_CURRENT (fns);
2977 if (DECL_VINDEX (fndecl))
2978 mark_overriders (fndecl, base_fndecls);
2981 /* Now give a warning for all base functions without overriders,
2982 as they are hidden. */
2983 for (; base_fndecls; base_fndecls = TREE_CHAIN (base_fndecls))
2985 if (! overrides (TREE_PURPOSE (base_fndecls),
2986 TREE_VALUE (base_fndecls)))
2988 /* Here we know it is a hider, and no overrider exists. */
2989 cp_warning_at ("`%D' was hidden", TREE_VALUE (base_fndecls));
2990 cp_warning_at (" by `%D'", TREE_PURPOSE (base_fndecls));
2996 /* Check for things that are invalid. There are probably plenty of other
2997 things we should check for also. */
3000 finish_struct_anon (t)
3005 for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
3007 if (TREE_STATIC (field))
3009 if (TREE_CODE (field) != FIELD_DECL)
3012 if (DECL_NAME (field) == NULL_TREE
3013 && ANON_AGGR_TYPE_P (TREE_TYPE (field)))
3015 tree elt = TYPE_FIELDS (TREE_TYPE (field));
3016 for (; elt; elt = TREE_CHAIN (elt))
3018 if (DECL_ARTIFICIAL (elt))
3021 if (DECL_NAME (elt) == constructor_name (t))
3022 cp_pedwarn_at ("ANSI C++ forbids member `%D' with same name as enclosing class",
3025 if (TREE_CODE (elt) != FIELD_DECL)
3027 cp_pedwarn_at ("`%#D' invalid; an anonymous union can only have non-static data members",
3032 if (TREE_PRIVATE (elt))
3033 cp_pedwarn_at ("private member `%#D' in anonymous union",
3035 else if (TREE_PROTECTED (elt))
3036 cp_pedwarn_at ("protected member `%#D' in anonymous union",
3039 TREE_PRIVATE (elt) = TREE_PRIVATE (field);
3040 TREE_PROTECTED (elt) = TREE_PROTECTED (field);
3046 extern int interface_only, interface_unknown;
3048 /* Create default constructors, assignment operators, and so forth for
3049 the type indicated by T, if they are needed.
3050 CANT_HAVE_DEFAULT_CTOR, CANT_HAVE_CONST_CTOR, and
3051 CANT_HAVE_ASSIGNMENT are nonzero if, for whatever reason, the class
3052 cannot have a default constructor, copy constructor taking a const
3053 reference argument, or an assignment operator, respectively. If a
3054 virtual destructor is created, its DECL is returned; otherwise the
3055 return value is NULL_TREE. */
3058 add_implicitly_declared_members (t, cant_have_default_ctor,
3059 cant_have_const_cctor,
3060 cant_have_assignment)
3062 int cant_have_default_ctor;
3063 int cant_have_const_cctor;
3064 int cant_have_assignment;
3067 tree implicit_fns = NULL_TREE;
3068 tree name = TYPE_IDENTIFIER (t);
3069 tree virtual_dtor = NULL_TREE;
3073 if (TYPE_NEEDS_DESTRUCTOR (t) && !TYPE_HAS_DESTRUCTOR (t))
3075 default_fn = cons_up_default_function (t, name, 0);
3076 check_for_override (default_fn, t);
3078 /* If we couldn't make it work, then pretend we didn't need it. */
3079 if (default_fn == void_type_node)
3080 TYPE_NEEDS_DESTRUCTOR (t) = 0;
3083 TREE_CHAIN (default_fn) = implicit_fns;
3084 implicit_fns = default_fn;
3086 if (DECL_VINDEX (default_fn))
3087 virtual_dtor = default_fn;
3090 TYPE_NEEDS_DESTRUCTOR (t) |= TYPE_HAS_DESTRUCTOR (t);
3092 /* Default constructor. */
3093 if (! TYPE_HAS_CONSTRUCTOR (t) && ! cant_have_default_ctor)
3095 default_fn = cons_up_default_function (t, name, 2);
3096 TREE_CHAIN (default_fn) = implicit_fns;
3097 implicit_fns = default_fn;
3100 /* Copy constructor. */
3101 if (! TYPE_HAS_INIT_REF (t) && ! TYPE_FOR_JAVA (t))
3103 /* ARM 12.18: You get either X(X&) or X(const X&), but
3105 default_fn = cons_up_default_function (t, name,
3106 3 + cant_have_const_cctor);
3107 TREE_CHAIN (default_fn) = implicit_fns;
3108 implicit_fns = default_fn;
3111 /* Assignment operator. */
3112 if (! TYPE_HAS_ASSIGN_REF (t) && ! TYPE_FOR_JAVA (t))
3114 default_fn = cons_up_default_function (t, name,
3115 5 + cant_have_assignment);
3116 TREE_CHAIN (default_fn) = implicit_fns;
3117 implicit_fns = default_fn;
3120 /* Now, hook all of the new functions on to TYPE_METHODS,
3121 and add them to the CLASSTYPE_METHOD_VEC. */
3122 for (f = &implicit_fns; *f; f = &TREE_CHAIN (*f))
3123 add_method (t, 0, *f);
3124 *f = TYPE_METHODS (t);
3125 TYPE_METHODS (t) = implicit_fns;
3127 return virtual_dtor;
3130 /* Subroutine of finish_struct_1. Recursively count the number of fields
3131 in TYPE, including anonymous union members. */
3134 count_fields (fields)
3139 for (x = fields; x; x = TREE_CHAIN (x))
3141 if (TREE_CODE (x) == FIELD_DECL && ANON_AGGR_TYPE_P (TREE_TYPE (x)))
3142 n_fields += count_fields (TYPE_FIELDS (TREE_TYPE (x)));
3149 /* Subroutine of finish_struct_1. Recursively add all the fields in the
3150 TREE_LIST FIELDS to the TREE_VEC FIELD_VEC, starting at offset IDX. */
3153 add_fields_to_vec (fields, field_vec, idx)
3154 tree fields, field_vec;
3158 for (x = fields; x; x = TREE_CHAIN (x))
3160 if (TREE_CODE (x) == FIELD_DECL && ANON_AGGR_TYPE_P (TREE_TYPE (x)))
3161 idx = add_fields_to_vec (TYPE_FIELDS (TREE_TYPE (x)), field_vec, idx);
3163 TREE_VEC_ELT (field_vec, idx++) = x;
3168 /* FIELD is a bit-field. We are finishing the processing for its
3169 enclosing type. Issue any appropriate messages and set appropriate
3173 check_bitfield_decl (field)
3176 tree type = TREE_TYPE (field);
3178 /* Invalid bit-field size done by grokfield. */
3179 /* Detect invalid bit-field type. Simply checking if TYPE is
3180 integral is insufficient, as that is the array core of the field
3181 type. If TREE_TYPE (field) is integral, then TYPE must be the same. */
3182 if (DECL_INITIAL (field)
3183 && ! INTEGRAL_TYPE_P (TREE_TYPE (field)))
3185 cp_error_at ("bit-field `%#D' with non-integral type", field);
3186 DECL_INITIAL (field) = NULL;
3189 /* Detect and ignore out of range field width. */
3190 if (DECL_INITIAL (field))
3192 tree w = DECL_INITIAL (field);
3193 register int width = 0;
3195 /* Avoid the non_lvalue wrapper added by fold for PLUS_EXPRs. */
3198 /* detect invalid field size. */
3199 if (TREE_CODE (w) == CONST_DECL)
3200 w = DECL_INITIAL (w);
3201 else if (TREE_READONLY_DECL_P (w))
3202 w = decl_constant_value (w);
3204 if (TREE_CODE (w) != INTEGER_CST)
3206 cp_error_at ("bit-field `%D' width not an integer constant",
3208 DECL_INITIAL (field) = NULL_TREE;
3210 else if (width = TREE_INT_CST_LOW (w),
3213 DECL_INITIAL (field) = NULL;
3214 cp_error_at ("negative width in bit-field `%D'", field);
3216 else if (width == 0 && DECL_NAME (field) != 0)
3218 DECL_INITIAL (field) = NULL;
3219 cp_error_at ("zero width for bit-field `%D'", field);
3222 > TYPE_PRECISION (long_long_unsigned_type_node))
3224 /* The backend will dump if you try to use something too
3226 DECL_INITIAL (field) = NULL;
3227 sorry ("bit-fields larger than %d bits",
3228 TYPE_PRECISION (long_long_unsigned_type_node));
3229 cp_error_at (" in declaration of `%D'", field);
3231 else if (width > TYPE_PRECISION (type)
3232 && TREE_CODE (type) != ENUMERAL_TYPE
3233 && TREE_CODE (type) != BOOLEAN_TYPE)
3234 cp_warning_at ("width of `%D' exceeds its type", field);
3235 else if (TREE_CODE (type) == ENUMERAL_TYPE
3236 && ((min_precision (TYPE_MIN_VALUE (type),
3237 TREE_UNSIGNED (type)) > width)
3238 || (min_precision (TYPE_MAX_VALUE (type),
3239 TREE_UNSIGNED (type)) > width)))
3240 cp_warning_at ("`%D' is too small to hold all values of `%#T'",
3243 if (DECL_INITIAL (field))
3245 DECL_INITIAL (field) = NULL_TREE;
3246 DECL_FIELD_SIZE (field) = width;
3247 DECL_BIT_FIELD (field) = 1;
3251 #ifdef EMPTY_FIELD_BOUNDARY
3252 DECL_ALIGN (field) = MAX (DECL_ALIGN (field),
3253 EMPTY_FIELD_BOUNDARY);
3255 #ifdef PCC_BITFIELD_TYPE_MATTERS
3256 if (PCC_BITFIELD_TYPE_MATTERS)
3257 DECL_ALIGN (field) = MAX (DECL_ALIGN (field),
3264 /* Non-bit-fields are aligned for their type. */
3265 DECL_ALIGN (field) = MAX (DECL_ALIGN (field), TYPE_ALIGN (type));
3268 /* FIELD is a non bit-field. We are finishing the processing for its
3269 enclosing type T. Issue any appropriate messages and set appropriate
3273 check_field_decl (field, t, cant_have_const_ctor,
3274 cant_have_default_ctor, no_const_asn_ref,
3275 any_default_members)
3278 int *cant_have_const_ctor;
3279 int *cant_have_default_ctor;
3280 int *no_const_asn_ref;
3281 int *any_default_members;
3283 tree type = strip_array_types (TREE_TYPE (field));
3285 /* An anonymous union cannot contain any fields which would change
3286 the settings of CANT_HAVE_CONST_CTOR and friends. */
3287 if (ANON_UNION_TYPE_P (type))
3289 /* And, we don't set TYPE_HAS_CONST_INIT_REF, etc., for anonymous
3290 structs. So, we recurse through their fields here. */
3291 else if (ANON_AGGR_TYPE_P (type))
3295 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
3296 if (TREE_CODE (field) == FIELD_DECL && !DECL_C_BIT_FIELD (field))
3297 check_field_decl (fields, t, cant_have_const_ctor,
3298 cant_have_default_ctor, no_const_asn_ref,
3299 any_default_members);
3301 /* Check members with class type for constructors, destructors,
3303 else if (CLASS_TYPE_P (type))
3305 /* Never let anything with uninheritable virtuals
3306 make it through without complaint. */
3307 abstract_virtuals_error (field, type);
3309 if (TREE_CODE (t) == UNION_TYPE)
3311 if (TYPE_NEEDS_CONSTRUCTING (type))
3312 cp_error_at ("member `%#D' with constructor not allowed in union",
3314 if (TYPE_NEEDS_DESTRUCTOR (type))
3315 cp_error_at ("member `%#D' with destructor not allowed in union",
3317 if (TYPE_HAS_COMPLEX_ASSIGN_REF (type))
3318 cp_error_at ("member `%#D' with copy assignment operator not allowed in union",
3323 TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (type);
3324 TYPE_NEEDS_DESTRUCTOR (t) |= TYPE_NEEDS_DESTRUCTOR (type);
3325 TYPE_HAS_COMPLEX_ASSIGN_REF (t) |= TYPE_HAS_COMPLEX_ASSIGN_REF (type);
3326 TYPE_HAS_COMPLEX_INIT_REF (t) |= TYPE_HAS_COMPLEX_INIT_REF (type);
3329 if (!TYPE_HAS_CONST_INIT_REF (type))
3330 *cant_have_const_ctor = 1;
3332 if (!TYPE_HAS_CONST_ASSIGN_REF (type))
3333 *no_const_asn_ref = 1;
3335 if (TYPE_HAS_CONSTRUCTOR (type)
3336 && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (type))
3337 *cant_have_default_ctor = 1;
3339 if (DECL_INITIAL (field) != NULL_TREE)
3341 /* `build_class_init_list' does not recognize
3343 if (TREE_CODE (t) == UNION_TYPE && any_default_members != 0)
3344 cp_error_at ("multiple fields in union `%T' initialized");
3345 *any_default_members = 1;
3348 /* Non-bit-fields are aligned for their type, except packed fields
3349 which require only BITS_PER_UNIT alignment. */
3350 DECL_ALIGN (field) = MAX (DECL_ALIGN (field),
3351 (DECL_PACKED (field)
3353 : TYPE_ALIGN (TREE_TYPE (field))));
3356 /* Check the data members (both static and non-static), class-scoped
3357 typedefs, etc., appearing in the declaration of T. Issue
3358 appropriate diagnostics. Sets ACCESS_DECLS to a list (in
3359 declaration order) of access declarations; each TREE_VALUE in this
3360 list is a USING_DECL.
3362 In addition, set the following flags:
3365 The class is empty, i.e., contains no non-static data members.
3367 CANT_HAVE_DEFAULT_CTOR_P
3368 This class cannot have an implicitly generated default
3371 CANT_HAVE_CONST_CTOR_P
3372 This class cannot have an implicitly generated copy constructor
3373 taking a const reference.
3375 CANT_HAVE_CONST_ASN_REF
3376 This class cannot have an implicitly generated assignment
3377 operator taking a const reference.
3379 All of these flags should be initialized before calling this
3382 Returns a pointer to the end of the TYPE_FIELDs chain; additional
3383 fields can be added by adding to this chain. */
3386 check_field_decls (t, access_decls, empty_p,
3387 cant_have_default_ctor_p, cant_have_const_ctor_p,
3392 int *cant_have_default_ctor_p;
3393 int *cant_have_const_ctor_p;
3394 int *no_const_asn_ref_p;
3399 int any_default_members;
3401 /* First, delete any duplicate fields. */
3402 delete_duplicate_fields (TYPE_FIELDS (t));
3404 /* Assume there are no access declarations. */
3405 *access_decls = NULL_TREE;
3406 /* Assume this class has no pointer members. */
3408 /* Assume none of the members of this class have default
3410 any_default_members = 0;
3412 for (field = &TYPE_FIELDS (t); *field; field = next)
3415 tree type = TREE_TYPE (x);
3417 GNU_xref_member (current_class_name, x);
3419 next = &TREE_CHAIN (x);
3421 if (TREE_CODE (x) == FIELD_DECL)
3423 DECL_PACKED (x) |= TYPE_PACKED (t);
3425 if (DECL_C_BIT_FIELD (x) && integer_zerop (DECL_INITIAL (x)))
3426 /* We don't treat zero-width bitfields as making a class
3431 /* The class is non-empty. */
3433 /* The class is not even nearly empty. */
3434 CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
3438 if (TREE_CODE (x) == USING_DECL)
3440 /* Prune the access declaration from the list of fields. */
3441 *field = TREE_CHAIN (x);
3443 /* Save the access declarations for our caller. */
3444 *access_decls = tree_cons (NULL_TREE, x, *access_decls);
3446 /* Since we've reset *FIELD there's no reason to skip to the
3452 if (TREE_CODE (x) == TYPE_DECL
3453 || TREE_CODE (x) == TEMPLATE_DECL)
3456 /* If we've gotten this far, it's a data member, possibly static,
3457 or an enumerator. */
3459 DECL_FIELD_CONTEXT (x) = t;
3461 /* ``A local class cannot have static data members.'' ARM 9.4 */
3462 if (current_function_decl && TREE_STATIC (x))
3463 cp_error_at ("field `%D' in local class cannot be static", x);
3465 /* Perform error checking that did not get done in
3467 if (TREE_CODE (type) == FUNCTION_TYPE)
3469 cp_error_at ("field `%D' invalidly declared function type",
3471 type = build_pointer_type (type);
3472 TREE_TYPE (x) = type;
3474 else if (TREE_CODE (type) == METHOD_TYPE)
3476 cp_error_at ("field `%D' invalidly declared method type", x);
3477 type = build_pointer_type (type);
3478 TREE_TYPE (x) = type;
3480 else if (TREE_CODE (type) == OFFSET_TYPE)
3482 cp_error_at ("field `%D' invalidly declared offset type", x);
3483 type = build_pointer_type (type);
3484 TREE_TYPE (x) = type;
3487 if (type == error_mark_node)
3490 DECL_SAVED_INSNS (x) = 0;
3491 DECL_FIELD_SIZE (x) = 0;
3493 /* When this goes into scope, it will be a non-local reference. */
3494 DECL_NONLOCAL (x) = 1;
3496 if (TREE_CODE (x) == CONST_DECL)
3499 if (TREE_CODE (x) == VAR_DECL)
3501 if (TREE_CODE (t) == UNION_TYPE)
3502 /* Unions cannot have static members. */
3503 cp_error_at ("field `%D' declared static in union", x);
3508 /* Now it can only be a FIELD_DECL. */
3510 if (TREE_PRIVATE (x) || TREE_PROTECTED (x))
3511 CLASSTYPE_NON_AGGREGATE (t) = 1;
3513 /* If this is of reference type, check if it needs an init.
3514 Also do a little ANSI jig if necessary. */
3515 if (TREE_CODE (type) == REFERENCE_TYPE)
3517 CLASSTYPE_NON_POD_P (t) = 1;
3518 if (DECL_INITIAL (x) == NULL_TREE)
3519 CLASSTYPE_REF_FIELDS_NEED_INIT (t) = 1;
3521 /* ARM $12.6.2: [A member initializer list] (or, for an
3522 aggregate, initialization by a brace-enclosed list) is the
3523 only way to initialize nonstatic const and reference
3525 *cant_have_default_ctor_p = 1;
3526 TYPE_HAS_COMPLEX_ASSIGN_REF (t) = 1;
3528 if (! TYPE_HAS_CONSTRUCTOR (t) && extra_warnings)
3531 cp_warning_at ("non-static reference `%#D' in class without a constructor", x);
3533 cp_warning_at ("non-static reference in class without a constructor", x);
3537 type = strip_array_types (type);
3539 if (TREE_CODE (type) == POINTER_TYPE)
3542 if (DECL_MUTABLE_P (x) || TYPE_HAS_MUTABLE_P (type))
3543 CLASSTYPE_HAS_MUTABLE (t) = 1;
3545 if (! pod_type_p (type)
3546 /* For some reason, pointers to members are POD types themselves,
3547 but are not allowed in POD structs. Silly. */
3548 || TYPE_PTRMEM_P (type) || TYPE_PTRMEMFUNC_P (type))
3549 CLASSTYPE_NON_POD_P (t) = 1;
3551 /* If any field is const, the structure type is pseudo-const. */
3552 if (CP_TYPE_CONST_P (type))
3554 C_TYPE_FIELDS_READONLY (t) = 1;
3555 if (DECL_INITIAL (x) == NULL_TREE)
3556 CLASSTYPE_READONLY_FIELDS_NEED_INIT (t) = 1;
3558 /* ARM $12.6.2: [A member initializer list] (or, for an
3559 aggregate, initialization by a brace-enclosed list) is the
3560 only way to initialize nonstatic const and reference
3562 *cant_have_default_ctor_p = 1;
3563 TYPE_HAS_COMPLEX_ASSIGN_REF (t) = 1;
3565 if (! TYPE_HAS_CONSTRUCTOR (t) && extra_warnings)
3568 cp_warning_at ("non-static const member `%#D' in class without a constructor", x);
3570 cp_warning_at ("non-static const member in class without a constructor", x);
3573 /* A field that is pseudo-const makes the structure likewise. */
3574 else if (IS_AGGR_TYPE (type))
3576 C_TYPE_FIELDS_READONLY (t) |= C_TYPE_FIELDS_READONLY (type);
3577 CLASSTYPE_READONLY_FIELDS_NEED_INIT (t)
3578 |= CLASSTYPE_READONLY_FIELDS_NEED_INIT (type);
3581 /* We set DECL_C_BIT_FIELD in grokbitfield.
3582 If the type and width are valid, we'll also set DECL_BIT_FIELD. */
3583 if (DECL_C_BIT_FIELD (x))
3584 check_bitfield_decl (x);
3586 check_field_decl (x, t,
3587 cant_have_const_ctor_p,
3588 cant_have_default_ctor_p,
3590 &any_default_members);
3593 /* Effective C++ rule 11. */
3594 if (has_pointers && warn_ecpp && TYPE_HAS_CONSTRUCTOR (t)
3595 && ! (TYPE_HAS_INIT_REF (t) && TYPE_HAS_ASSIGN_REF (t)))
3597 cp_warning ("`%#T' has pointer data members", t);
3599 if (! TYPE_HAS_INIT_REF (t))
3601 cp_warning (" but does not override `%T(const %T&)'", t, t);
3602 if (! TYPE_HAS_ASSIGN_REF (t))
3603 cp_warning (" or `operator=(const %T&)'", t);
3605 else if (! TYPE_HAS_ASSIGN_REF (t))
3606 cp_warning (" but does not override `operator=(const %T&)'", t);
3610 /* Check anonymous struct/anonymous union fields. */
3611 finish_struct_anon (t);
3613 /* We've built up the list of access declarations in reverse order.
3615 *access_decls = nreverse (*access_decls);
3618 /* Return a FIELD_DECL for a pointer-to-virtual-table or
3619 pointer-to-virtual-base. The NAME, ASSEMBLER_NAME, and TYPE of the
3620 field are as indicated. The CLASS_TYPE in which this field occurs
3621 is also indicated. *EMPTY_P is set to a non-zero value by this
3622 function to indicate that a class containing this field is
3626 build_vtbl_or_vbase_field (name, assembler_name, type, class_type,
3629 tree assembler_name;
3636 /* This class is non-empty. */
3639 /* Build the FIELD_DECL. */
3640 field = build_lang_decl (FIELD_DECL, name, type);
3641 DECL_ASSEMBLER_NAME (field) = assembler_name;
3642 DECL_VIRTUAL_P (field) = 1;
3643 DECL_ARTIFICIAL (field) = 1;
3644 DECL_FIELD_CONTEXT (field) = class_type;
3645 DECL_CLASS_CONTEXT (field) = class_type;
3646 DECL_FCONTEXT (field) = class_type;
3647 DECL_SAVED_INSNS (field) = 0;
3648 DECL_FIELD_SIZE (field) = 0;
3649 DECL_ALIGN (field) = TYPE_ALIGN (type);
3655 /* Returns list of virtual base class pointers in a FIELD_DECL chain. */
3658 build_vbase_pointer_fields (rec, empty_p)
3662 /* Chain to hold all the new FIELD_DECLs which point at virtual
3664 tree vbase_decls = NULL_TREE;
3665 tree binfos = TYPE_BINFO_BASETYPES (rec);
3666 int n_baseclasses = CLASSTYPE_N_BASECLASSES (rec);
3670 /* Handle basetypes almost like fields, but record their
3671 offsets differently. */
3673 for (i = 0; i < n_baseclasses; i++)
3675 register tree base_binfo = TREE_VEC_ELT (binfos, i);
3676 register tree basetype = BINFO_TYPE (base_binfo);
3678 if (TYPE_SIZE (basetype) == 0)
3679 /* This error is now reported in xref_tag, thus giving better
3680 location information. */
3683 /* All basetypes are recorded in the association list of the
3686 if (TREE_VIA_VIRTUAL (base_binfo))
3691 /* The offset for a virtual base class is only used in computing
3692 virtual function tables and for initializing virtual base
3693 pointers. It is built once `get_vbase_types' is called. */
3695 /* If this basetype can come from another vbase pointer
3696 without an additional indirection, we will share
3697 that pointer. If an indirection is involved, we
3698 make our own pointer. */
3699 for (j = 0; j < n_baseclasses; j++)
3701 tree other_base_binfo = TREE_VEC_ELT (binfos, j);
3702 if (! TREE_VIA_VIRTUAL (other_base_binfo)
3703 && BINFO_FOR_VBASE (basetype, BINFO_TYPE (other_base_binfo)))
3706 FORMAT_VBASE_NAME (name, basetype);
3707 decl = build_vtbl_or_vbase_field (get_identifier (name),
3708 get_identifier (VTABLE_BASE),
3709 build_pointer_type (basetype),
3712 BINFO_VPTR_FIELD (base_binfo) = decl;
3713 TREE_CHAIN (decl) = vbase_decls;
3718 /* The space this decl occupies has already been accounted for. */
3726 /* If the empty base field in DECL overlaps with a base of the same type in
3727 NEWDECL, which is either another base field or the first data field of
3728 the class, pad the base just before NEWDECL and return 1. Otherwise,
3732 avoid_overlap (decl, newdecl, empty_p)
3738 if (newdecl == NULL_TREE
3739 || ! types_overlap_p (TREE_TYPE (decl), TREE_TYPE (newdecl)))
3742 for (field = decl; TREE_CHAIN (field) && TREE_CHAIN (field) != newdecl;
3743 field = TREE_CHAIN (field))
3746 DECL_SIZE (field) = integer_one_node;
3747 /* The containing class cannot be empty; this field takes up space. */
3753 /* Build a FIELD_DECL for the base given by BINFO in T. If the new
3754 object is non-empty, clear *EMPTY_P. Otherwise, set *SAW_EMPTY_P.
3755 *BASE_ALIGN is a running maximum of the alignments of any base
3759 build_base_field (t, binfo, empty_p, saw_empty_p, base_align)
3764 unsigned int *base_align;
3766 tree basetype = BINFO_TYPE (binfo);
3769 if (TYPE_SIZE (basetype) == 0)
3770 /* This error is now reported in xref_tag, thus giving better
3771 location information. */
3774 decl = build_lang_decl (FIELD_DECL, NULL_TREE, basetype);
3775 DECL_ARTIFICIAL (decl) = 1;
3776 DECL_FIELD_CONTEXT (decl) = DECL_CLASS_CONTEXT (decl) = t;
3777 DECL_SIZE (decl) = CLASSTYPE_SIZE (basetype);
3778 DECL_ALIGN (decl) = CLASSTYPE_ALIGN (basetype);
3780 if (flag_new_abi && DECL_SIZE (decl) == integer_zero_node)
3786 /* The containing class is non-empty because it has a non-empty base
3792 /* Brain damage for backwards compatibility. For no good
3793 reason, the old layout_basetypes made every base at least
3794 as large as the alignment for the bases up to that point,
3795 gratuitously wasting space. So we do the same thing
3797 *base_align = MAX (*base_align, DECL_ALIGN (decl));
3799 = size_int (MAX (TREE_INT_CST_LOW (DECL_SIZE (decl)),
3800 (int) (*base_align)));
3806 /* Returns a list of fields to stand in for the base class subobjects
3807 of REC. These fields are later removed by layout_basetypes. */
3810 build_base_fields (rec, empty_p)
3814 /* Chain to hold all the new FIELD_DECLs which stand in for base class
3816 tree base_decls = NULL_TREE;
3817 int n_baseclasses = CLASSTYPE_N_BASECLASSES (rec);
3818 tree decl, nextdecl;
3819 int i, saw_empty = 0;
3820 unsigned int base_align = 0;
3822 /* Under the new ABI, the primary base class is always allocated
3824 if (flag_new_abi && CLASSTYPE_HAS_PRIMARY_BASE_P (rec))
3828 primary_base = CLASSTYPE_PRIMARY_BINFO (rec);
3829 base_decls = chainon (build_base_field (rec,
3837 /* Now allocate the rest of the bases. */
3838 for (i = 0; i < n_baseclasses; ++i)
3842 /* Under the new ABI, the primary base was already allocated
3843 above, so we don't need to allocate it again here. */
3844 if (flag_new_abi && i == CLASSTYPE_VFIELD_PARENT (rec))
3847 base_binfo = BINFO_BASETYPE (TYPE_BINFO (rec), i);
3849 /* A primary virtual base class is allocated just like any other
3850 base class, but a non-primary virtual base is allocated
3851 later, in layout_basetypes. */
3852 if (TREE_VIA_VIRTUAL (base_binfo)
3853 && !BINFO_PRIMARY_MARKED_P (base_binfo))
3856 base_decls = chainon (build_base_field (rec, base_binfo,
3863 /* Reverse the list of fields so we allocate the bases in the proper
3865 base_decls = nreverse (base_decls);
3867 /* In the presence of empty base classes, we run the risk of allocating
3868 two objects of the same class on top of one another. Avoid that. */
3869 if (flag_new_abi && saw_empty)
3870 for (decl = base_decls; decl; decl = TREE_CHAIN (decl))
3872 if (DECL_SIZE (decl) == integer_zero_node)
3874 /* First step through the following bases until we find
3875 an overlap or a non-empty base. */
3876 for (nextdecl = TREE_CHAIN (decl); nextdecl;
3877 nextdecl = TREE_CHAIN (nextdecl))
3879 if (avoid_overlap (decl, nextdecl, empty_p)
3880 || DECL_SIZE (nextdecl) != integer_zero_node)
3884 /* If we're still looking, also check against the first
3886 for (nextdecl = TYPE_FIELDS (rec);
3887 nextdecl && TREE_CODE (nextdecl) != FIELD_DECL;
3888 nextdecl = TREE_CHAIN (nextdecl))
3890 avoid_overlap (decl, nextdecl, empty_p);
3898 /* Go through the TYPE_METHODS of T issuing any appropriate
3899 diagnostics, figuring out which methods override which other
3900 methods, and so forth. */
3908 for (x = TYPE_METHODS (t); x; x = TREE_CHAIN (x))
3910 GNU_xref_member (current_class_name, x);
3912 /* If this was an evil function, don't keep it in class. */
3913 if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (x)))
3916 /* Do both of these, even though they're in the same union;
3917 if the insn `r' member and the size `i' member are
3918 different sizes, as on the alpha, the larger of the two
3919 will end up with garbage in it. */
3920 DECL_SAVED_INSNS (x) = 0;
3921 DECL_FIELD_SIZE (x) = 0;
3923 check_for_override (x, t);
3924 if (DECL_PURE_VIRTUAL_P (x) && ! DECL_VINDEX (x))
3925 cp_error_at ("initializer specified for non-virtual method `%D'", x);
3927 /* The name of the field is the original field name
3928 Save this in auxiliary field for later overloading. */
3929 if (DECL_VINDEX (x))
3931 TYPE_POLYMORPHIC_P (t) = 1;
3932 if (DECL_PURE_VIRTUAL_P (x))
3933 CLASSTYPE_PURE_VIRTUALS (t)
3934 = tree_cons (NULL_TREE, x, CLASSTYPE_PURE_VIRTUALS (t));
3939 /* Remove all zero-width bit-fields from T. */
3942 remove_zero_width_bit_fields (t)
3947 fieldsp = &TYPE_FIELDS (t);
3950 if (TREE_CODE (*fieldsp) == FIELD_DECL
3951 && DECL_C_BIT_FIELD (*fieldsp)
3952 && DECL_INITIAL (*fieldsp))
3953 *fieldsp = TREE_CHAIN (*fieldsp);
3955 fieldsp = &TREE_CHAIN (*fieldsp);
3959 /* Check the validity of the bases and members declared in T. Add any
3960 implicitly-generated functions (like copy-constructors and
3961 assignment operators). Compute various flag bits (like
3962 CLASSTYPE_NON_POD_T) for T. This routine works purely at the C++
3963 level: i.e., independently of the ABI in use. */
3966 check_bases_and_members (t, empty_p)
3970 /* Nonzero if we are not allowed to generate a default constructor
3972 int cant_have_default_ctor;
3973 /* Nonzero if the implicitly generated copy constructor should take
3974 a non-const reference argument. */
3975 int cant_have_const_ctor;
3976 /* Nonzero if the the implicitly generated assignment operator
3977 should take a non-const reference argument. */
3978 int no_const_asn_ref;
3981 /* By default, we use const reference arguments and generate default
3983 cant_have_default_ctor = 0;
3984 cant_have_const_ctor = 0;
3985 no_const_asn_ref = 0;
3987 /* Assume that the class is nearly empty; we'll clear this flag if
3988 it turns out not to be nearly empty. */
3989 CLASSTYPE_NEARLY_EMPTY_P (t) = 1;
3991 /* Check all the base-classes. */
3992 check_bases (t, &cant_have_default_ctor, &cant_have_const_ctor,
3995 /* Check all the data member declarations. */
3996 check_field_decls (t, &access_decls, empty_p,
3997 &cant_have_default_ctor,
3998 &cant_have_const_ctor,
4001 /* Check all the method declarations. */
4004 /* A nearly-empty class has to be polymorphic; a nearly empty class
4006 if (!TYPE_POLYMORPHIC_P (t))
4007 CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
4009 /* Do some bookkeeping that will guide the generation of implicitly
4010 declared member functions. */
4011 TYPE_HAS_COMPLEX_INIT_REF (t)
4012 |= (TYPE_HAS_INIT_REF (t)
4013 || TYPE_USES_VIRTUAL_BASECLASSES (t)
4014 || TYPE_POLYMORPHIC_P (t));
4015 TYPE_NEEDS_CONSTRUCTING (t)
4016 |= (TYPE_HAS_CONSTRUCTOR (t)
4017 || TYPE_USES_VIRTUAL_BASECLASSES (t)
4018 || TYPE_POLYMORPHIC_P (t));
4019 CLASSTYPE_NON_AGGREGATE (t) |= (TYPE_HAS_CONSTRUCTOR (t)
4020 || TYPE_POLYMORPHIC_P (t));
4021 CLASSTYPE_NON_POD_P (t)
4022 |= (CLASSTYPE_NON_AGGREGATE (t) || TYPE_HAS_DESTRUCTOR (t)
4023 || TYPE_HAS_ASSIGN_REF (t));
4024 TYPE_HAS_REAL_ASSIGN_REF (t) |= TYPE_HAS_ASSIGN_REF (t);
4025 TYPE_HAS_COMPLEX_ASSIGN_REF (t)
4026 |= TYPE_HAS_ASSIGN_REF (t) || TYPE_USES_VIRTUAL_BASECLASSES (t);
4028 /* Synthesize any needed methods. Note that methods will be synthesized
4029 for anonymous unions; grok_x_components undoes that. */
4030 add_implicitly_declared_members (t, cant_have_default_ctor,
4031 cant_have_const_ctor,
4034 /* Build and sort the CLASSTYPE_METHOD_VEC. */
4035 finish_struct_methods (t);
4037 /* Process the access-declarations. We wait until now to do this
4038 because handle_using_decls requires that the CLASSTYPE_METHOD_VEC
4039 be set up correctly. */
4040 while (access_decls)
4042 handle_using_decl (TREE_VALUE (access_decls), t);
4043 access_decls = TREE_CHAIN (access_decls);
4047 /* If T needs a pointer to its virtual function table, set TYPE_VFIELD
4048 accordingly, and, if necessary, add the TYPE_VFIELD to the
4049 TYPE_FIELDS list. */
4052 create_vtable_ptr (t, empty_p, has_virtual_p,
4053 pending_virtuals_p, pending_hard_virtuals_p)
4057 tree *pending_virtuals_p;
4058 tree *pending_hard_virtuals_p;
4062 /* Loop over the virtual functions, adding them to our various
4064 for (fn = TYPE_METHODS (t); fn; fn = TREE_CHAIN (fn))
4065 if (DECL_VINDEX (fn))
4066 add_virtual_function (pending_virtuals_p, pending_hard_virtuals_p,
4067 has_virtual_p, fn, t);
4069 /* If we couldn't find an appropriate base class, create a new field
4071 if (*has_virtual_p && !TYPE_VFIELD (t))
4073 /* We build this decl with vtbl_ptr_type_node, which is a
4074 `vtable_entry_type*'. It might seem more precise to use
4075 `vtable_entry_type (*)[N]' where N is the number of firtual
4076 functions. However, that would require the vtable pointer in
4077 base classes to have a different type than the vtable pointer
4078 in derived classes. We could make that happen, but that
4079 still wouldn't solve all the problems. In particular, the
4080 type-based alias analysis code would decide that assignments
4081 to the base class vtable pointer can't alias assignments to
4082 the derived class vtable pointer, since they have different
4083 types. Thus, in an derived class destructor, where the base
4084 class constructor was inlined, we could generate bad code for
4085 setting up the vtable pointer.
4087 Therefore, we use one type for all vtable pointers. We still
4088 use a type-correct type; it's just doesn't indicate the array
4089 bounds. That's better than using `void*' or some such; it's
4090 cleaner, and it let's the alias analysis code know that these
4091 stores cannot alias stores to void*! */
4093 = build_vtbl_or_vbase_field (get_vfield_name (t),
4094 get_identifier (VFIELD_BASE),
4099 /* Add the new field to the list of fields in this class. */
4101 /* In the old ABI, the vtable pointer goes at the end of the
4103 TYPE_FIELDS (t) = chainon (TYPE_FIELDS (t), TYPE_VFIELD (t));
4106 /* But in the new ABI, the vtable pointer is the first thing
4108 TYPE_FIELDS (t) = chainon (TYPE_VFIELD (t), TYPE_FIELDS (t));
4109 /* If there were any baseclasses, they can't possibly be at
4110 offset zero any more, because that's where the vtable
4111 pointer is. So, converting to a base class is going to
4113 if (CLASSTYPE_N_BASECLASSES (t))
4114 TYPE_BASE_CONVS_MAY_REQUIRE_CODE_P (t) = 1;
4117 /* We can't yet add this new field to the list of all virtual
4118 function table pointers in this class. The
4119 modify_all_vtables function depends on this not being done.
4120 So, it is done later, in finish_struct_1. */
4124 /* Fixup the inline function given by INFO now that the class is
4128 fixup_pending_inline (info)
4129 struct pending_inline *info;
4134 tree fn = info->fndecl;
4136 args = DECL_ARGUMENTS (fn);
4139 DECL_CONTEXT (args) = fn;
4140 args = TREE_CHAIN (args);
4145 /* Fixup the inline methods and friends in TYPE now that TYPE is
4149 fixup_inline_methods (type)
4152 tree method = TYPE_METHODS (type);
4154 if (method && TREE_CODE (method) == TREE_VEC)
4156 if (TREE_VEC_ELT (method, 1))
4157 method = TREE_VEC_ELT (method, 1);
4158 else if (TREE_VEC_ELT (method, 0))
4159 method = TREE_VEC_ELT (method, 0);
4161 method = TREE_VEC_ELT (method, 2);
4164 /* Do inline member functions. */
4165 for (; method; method = TREE_CHAIN (method))
4166 fixup_pending_inline (DECL_PENDING_INLINE_INFO (method));
4169 for (method = CLASSTYPE_INLINE_FRIENDS (type);
4171 method = TREE_CHAIN (method))
4172 fixup_pending_inline (DECL_PENDING_INLINE_INFO (TREE_VALUE (method)));
4173 CLASSTYPE_INLINE_FRIENDS (type) = NULL_TREE;
4176 /* Called from propagate_binfo_offsets via dfs_walk. */
4179 dfs_propagate_binfo_offsets (binfo, data)
4183 tree offset = (tree) data;
4185 /* Update the BINFO_OFFSET for this base. */
4186 BINFO_OFFSET (binfo)
4187 = size_binop (PLUS_EXPR, BINFO_OFFSET (binfo), offset);
4189 SET_BINFO_MARKED (binfo);
4194 /* Add OFFSET to all base types of BINFO which is a base in the
4195 hierarchy dominated by T.
4197 OFFSET, which is a type offset, is number of bytes.
4199 Note that we don't have to worry about having two paths to the
4200 same base type, since this type owns its association list. */
4203 propagate_binfo_offsets (binfo, offset)
4208 dfs_propagate_binfo_offsets,
4209 dfs_skip_nonprimary_vbases_unmarkedp,
4213 dfs_skip_nonprimary_vbases_markedp,
4217 /* Remove *FIELD (which corresponds to the base given by BINFO) from
4218 the field list for T. */
4221 remove_base_field (t, binfo, field)
4226 tree basetype = BINFO_TYPE (binfo);
4229 my_friendly_assert (TREE_TYPE (*field) == basetype, 23897);
4231 if (get_base_distance (basetype, t, 0, (tree*)0) == -2)
4232 cp_warning ("direct base `%T' inaccessible in `%T' due to ambiguity",
4236 = size_int (CEIL (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (*field)),
4238 propagate_binfo_offsets (binfo, offset);
4240 /* Remove this field. */
4241 *field = TREE_CHAIN (*field);
4244 /* Remove the FIELD_DECLs created for T's base classes in
4245 build_base_fields. Simultaneously, update BINFO_OFFSET for all the
4246 bases, except for non-primary virtual baseclasses. */
4249 remove_base_fields (t)
4255 /* Now propagate offset information throughout the lattice.
4256 Simultaneously, remove the temporary FIELD_DECLS we created in
4257 build_base_fields to refer to base types. */
4258 field = &TYPE_FIELDS (t);
4259 if (TYPE_VFIELD (t) == *field)
4261 /* If this class did not have a primary base, we create a
4262 virtual function table pointer. It will be the first thing
4263 in the class, under the new ABI. Skip it; the base fields
4265 my_friendly_assert (flag_new_abi
4266 && !CLASSTYPE_HAS_PRIMARY_BASE_P (t),
4268 field = &TREE_CHAIN (*field);
4271 /* Under the new ABI, the primary base is always allocated first. */
4272 if (flag_new_abi && CLASSTYPE_HAS_PRIMARY_BASE_P (t))
4273 remove_base_field (t, CLASSTYPE_PRIMARY_BINFO (t), field);
4275 /* Now remove the rest of the bases. */
4276 for (i = 0; i < CLASSTYPE_N_BASECLASSES (t); i++)
4280 /* Under the new ABI, we've already removed the primary base
4282 if (flag_new_abi && i == CLASSTYPE_VFIELD_PARENT (t))
4285 binfo = BINFO_BASETYPE (TYPE_BINFO (t), i);
4287 /* We treat a primary virtual base class just like an ordinary base
4288 class. But, non-primary virtual bases are laid out later. */
4289 if (TREE_VIA_VIRTUAL (binfo) && !BINFO_PRIMARY_MARKED_P (binfo))
4292 remove_base_field (t, binfo, field);
4296 /* Called via dfs_walk from layout_virtual bases. */
4299 dfs_set_offset_for_shared_vbases (binfo, data)
4303 if (TREE_VIA_VIRTUAL (binfo) && BINFO_PRIMARY_MARKED_P (binfo))
4305 /* Update the shared copy. */
4308 shared_binfo = BINFO_FOR_VBASE (BINFO_TYPE (binfo), (tree) data);
4309 BINFO_OFFSET (shared_binfo) = BINFO_OFFSET (binfo);
4315 /* Called via dfs_walk from layout_virtual bases. */
4318 dfs_set_offset_for_unshared_vbases (binfo, data)
4322 /* If this is a virtual base, make sure it has the same offset as
4323 the shared copy. If it's a primary base, then we know it's
4325 if (TREE_VIA_VIRTUAL (binfo) && !BINFO_PRIMARY_MARKED_P (binfo))
4327 tree t = (tree) data;
4331 vbase = BINFO_FOR_VBASE (BINFO_TYPE (binfo), t);
4332 offset = ssize_binop (MINUS_EXPR,
4333 BINFO_OFFSET (vbase),
4334 BINFO_OFFSET (binfo));
4335 propagate_binfo_offsets (binfo, offset);
4341 /* Set BINFO_OFFSET for all of the virtual bases for T. Update
4342 TYPE_ALIGN and TYPE_SIZE for T. */
4345 layout_virtual_bases (t)
4351 /* DSIZE is the size of the class without the virtual bases. */
4352 dsize = TREE_INT_CST_LOW (TYPE_SIZE (t));
4353 /* Make every class have alignment of at least one. */
4354 TYPE_ALIGN (t) = MAX (TYPE_ALIGN (t), BITS_PER_UNIT);
4356 /* Go through the virtual bases, allocating space for each virtual
4357 base that is not already a primary base class. */
4358 for (vbase = CLASSTYPE_VBASECLASSES (t);
4360 vbase = TREE_CHAIN (vbase))
4361 if (!BINFO_VBASE_PRIMARY_P (vbase))
4363 /* This virtual base is not a primary base of any class in the
4364 hierarchy, so we have to add space for it. */
4366 unsigned int desired_align;
4368 basetype = BINFO_TYPE (vbase);
4369 desired_align = TYPE_ALIGN (basetype);
4370 TYPE_ALIGN (t) = MAX (TYPE_ALIGN (t), desired_align);
4372 /* Add padding so that we can put the virtual base class at an
4373 appropriately aligned offset. */
4374 dsize = CEIL (dsize, desired_align) * desired_align;
4375 /* And compute the offset of the virtual base. */
4376 propagate_binfo_offsets (vbase,
4377 size_int (CEIL (dsize, BITS_PER_UNIT)));
4378 /* Every virtual baseclass takes a least a UNIT, so that we can
4379 take it's address and get something different for each base. */
4380 dsize += MAX (BITS_PER_UNIT,
4381 TREE_INT_CST_LOW (CLASSTYPE_SIZE (basetype)));
4384 /* Make sure that all of the CLASSTYPE_VBASECLASSES have their
4385 BINFO_OFFSET set correctly. Those we just allocated certainly
4386 will. The others are primary baseclasses; we walk the hierarchy
4387 to find the primary copies and update the shared copy. */
4388 dfs_walk (TYPE_BINFO (t),
4389 dfs_set_offset_for_shared_vbases,
4390 dfs_unmarked_real_bases_queue_p,
4393 /* Now, go through the TYPE_BINFO hierarchy again, setting the
4394 BINFO_OFFSETs correctly for all non-primary copies of the virtual
4395 bases and their direct and indirect bases. The ambiguity checks
4396 in get_base_distance depend on the BINFO_OFFSETs being set
4398 dfs_walk (TYPE_BINFO (t), dfs_set_offset_for_unshared_vbases, NULL, t);
4400 /* Now, make sure that the total size of the type is a multiple of
4402 dsize = CEIL (dsize, TYPE_ALIGN (t)) * TYPE_ALIGN (t);
4403 TYPE_SIZE (t) = size_int (dsize);
4404 TYPE_SIZE_UNIT (t) = size_binop (FLOOR_DIV_EXPR, TYPE_SIZE (t),
4405 size_int (BITS_PER_UNIT));
4408 /* Finish the work of layout_record, now taking virtual bases into account.
4409 Also compute the actual offsets that our base classes will have.
4410 This must be performed after the fields are laid out, since virtual
4411 baseclasses must lay down at the end of the record. */
4414 layout_basetypes (rec)
4419 #ifdef STRUCTURE_SIZE_BOUNDARY
4420 /* Packed structures don't need to have minimum size. */
4421 if (! TYPE_PACKED (rec))
4422 TYPE_ALIGN (rec) = MAX (TYPE_ALIGN (rec), STRUCTURE_SIZE_BOUNDARY);
4425 /* Remove the FIELD_DECLs we created for baseclasses in
4426 build_base_fields. Simultaneously, update the BINFO_OFFSETs for
4427 everything in the hierarcy except non-primary virtual bases. */
4428 remove_base_fields (rec);
4430 /* Allocate the virtual base classes. */
4431 layout_virtual_bases (rec);
4433 /* Get all the virtual base types that this type uses. The
4434 TREE_VALUE slot holds the virtual baseclass type. Note that
4435 get_vbase_types makes copies of the virtual base BINFOs, so that
4436 the vbase_types are unshared. */
4437 for (vbase_types = CLASSTYPE_VBASECLASSES (rec); vbase_types;
4438 vbase_types = TREE_CHAIN (vbase_types))
4441 tree basetype = BINFO_TYPE (vbase_types);
4442 if (get_base_distance (basetype, rec, 0, (tree*)0) == -2)
4443 cp_warning ("virtual base `%T' inaccessible in `%T' due to ambiguity",
4448 /* Calculate the TYPE_SIZE, TYPE_ALIGN, etc for T. Calculate
4449 BINFO_OFFSETs for all of the base-classes. Position the vtable
4453 layout_class_type (t, empty_p, has_virtual_p,
4454 pending_virtuals_p, pending_hard_virtuals_p)
4458 tree *pending_virtuals_p;
4459 tree *pending_hard_virtuals_p;
4461 /* If possible, we reuse the virtual function table pointer from one
4462 of our base classes. */
4463 determine_primary_base (t, has_virtual_p);
4465 /* Add pointers to all of our virtual base-classes. */
4466 TYPE_FIELDS (t) = chainon (build_vbase_pointer_fields (t, empty_p),
4468 /* Build FIELD_DECLs for all of the non-virtual base-types. */
4469 TYPE_FIELDS (t) = chainon (build_base_fields (t, empty_p),
4472 /* Create a pointer to our virtual function table. */
4473 create_vtable_ptr (t, empty_p, has_virtual_p,
4474 pending_virtuals_p, pending_hard_virtuals_p);
4476 /* CLASSTYPE_INLINE_FRIENDS is really TYPE_NONCOPIED_PARTS. Thus,
4477 we have to save this before we start modifying
4478 TYPE_NONCOPIED_PARTS. */
4479 fixup_inline_methods (t);
4481 /* We make all structures have at least one element, so that they
4482 have non-zero size. The field that we add here is fake, in the
4483 sense that, for example, we don't want people to be able to
4484 initialize it later. So, we add it just long enough to let the
4485 back-end lay out the type, and then remove it. */
4488 tree decl = build_lang_decl
4489 (FIELD_DECL, NULL_TREE, char_type_node);
4490 TREE_CHAIN (decl) = TYPE_FIELDS (t);
4491 TYPE_FIELDS (t) = decl;
4492 TYPE_NONCOPIED_PARTS (t)
4493 = tree_cons (NULL_TREE, decl, TYPE_NONCOPIED_PARTS (t));
4494 TREE_STATIC (TYPE_NONCOPIED_PARTS (t)) = 1;
4497 /* Let the back-end lay out the type. Note that at this point we
4498 have only included non-virtual base-classes; we will lay out the
4499 virtual base classes later. So, the TYPE_SIZE/TYPE_ALIGN after
4500 this call are not necessarily correct; they are just the size and
4501 alignment when no virtual base clases are used. */
4504 /* If we added an extra field to make this class non-empty, remove
4507 TYPE_FIELDS (t) = TREE_CHAIN (TYPE_FIELDS (t));
4509 /* Delete all zero-width bit-fields from the list of fields. Now
4510 that the type is laid out they are no longer important. */
4511 remove_zero_width_bit_fields (t);
4513 /* Remember the size and alignment of the class before adding
4514 the virtual bases. */
4515 if (*empty_p && flag_new_abi)
4516 CLASSTYPE_SIZE (t) = integer_zero_node;
4517 else if (flag_new_abi && TYPE_HAS_COMPLEX_INIT_REF (t)
4518 && TYPE_HAS_COMPLEX_ASSIGN_REF (t))
4519 CLASSTYPE_SIZE (t) = TYPE_BINFO_SIZE (t);
4521 CLASSTYPE_SIZE (t) = TYPE_SIZE (t);
4522 CLASSTYPE_ALIGN (t) = TYPE_ALIGN (t);
4524 /* Set the TYPE_DECL for this type to contain the right
4525 value for DECL_OFFSET, so that we can use it as part
4526 of a COMPONENT_REF for multiple inheritance. */
4527 layout_decl (TYPE_MAIN_DECL (t), 0);
4529 /* Now fix up any virtual base class types that we left lying
4530 around. We must get these done before we try to lay out the
4531 virtual function table. */
4532 if (CLASSTYPE_N_BASECLASSES (t))
4533 /* layout_basetypes will remove the base subobject fields. */
4534 layout_basetypes (t);
4537 /* Create a RECORD_TYPE or UNION_TYPE node for a C struct or union declaration
4538 (or C++ class declaration).
4540 For C++, we must handle the building of derived classes.
4541 Also, C++ allows static class members. The way that this is
4542 handled is to keep the field name where it is (as the DECL_NAME
4543 of the field), and place the overloaded decl in the DECL_FIELD_BITPOS
4544 of the field. layout_record and layout_union will know about this.
4546 More C++ hair: inline functions have text in their
4547 DECL_PENDING_INLINE_INFO nodes which must somehow be parsed into
4548 meaningful tree structure. After the struct has been laid out, set
4549 things up so that this can happen.
4551 And still more: virtual functions. In the case of single inheritance,
4552 when a new virtual function is seen which redefines a virtual function
4553 from the base class, the new virtual function is placed into
4554 the virtual function table at exactly the same address that
4555 it had in the base class. When this is extended to multiple
4556 inheritance, the same thing happens, except that multiple virtual
4557 function tables must be maintained. The first virtual function
4558 table is treated in exactly the same way as in the case of single
4559 inheritance. Additional virtual function tables have different
4560 DELTAs, which tell how to adjust `this' to point to the right thing.
4562 ATTRIBUTES is the set of decl attributes to be applied, if any. */
4570 tree pending_virtuals = NULL_TREE;
4571 tree pending_hard_virtuals = NULL_TREE;
4578 if (IS_AGGR_TYPE (t))
4579 cp_error ("redefinition of `%#T'", t);
4581 my_friendly_abort (172);
4586 GNU_xref_decl (current_function_decl, t);
4588 /* If this type was previously laid out as a forward reference,
4589 make sure we lay it out again. */
4591 TYPE_SIZE (t) = NULL_TREE;
4592 CLASSTYPE_GOT_SEMICOLON (t) = 0;
4593 CLASSTYPE_VFIELD_PARENT (t) = -1;
4595 CLASSTYPE_RTTI (t) = NULL_TREE;
4597 /* Do end-of-class semantic processing: checking the validity of the
4598 bases and members and add implicitly generated methods. */
4599 check_bases_and_members (t, &empty);
4601 /* Layout the class itself. */
4602 layout_class_type (t, &empty, &has_virtual,
4603 &pending_virtuals, &pending_hard_virtuals);
4605 if (TYPE_USES_VIRTUAL_BASECLASSES (t))
4609 vbases = CLASSTYPE_VBASECLASSES (t);
4612 /* Now fixup overrides of all functions in vtables from all
4613 direct or indirect virtual base classes. */
4614 tree binfos = BINFO_BASETYPES (TYPE_BINFO (t));
4615 int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
4617 for (i = 0; i < n_baseclasses; i++)
4619 tree base_binfo = TREE_VEC_ELT (binfos, i);
4620 tree basetype = BINFO_TYPE (base_binfo);
4623 vbases = CLASSTYPE_VBASECLASSES (basetype);
4627 tree basetype_vbase;
4630 = find_vbase_instance (BINFO_TYPE (vbases), t);
4632 = find_vbase_instance (BINFO_TYPE (vbases), basetype);
4634 merge_overrides (vbase, basetype_vbase, 1, t);
4635 vbases = TREE_CHAIN (vbases);
4641 /* Set up the DECL_FIELD_BITPOS of the vfield if we need to, as we
4642 might need to know it for setting up the offsets in the vtable
4643 (or in thunks) below. */
4644 vfield = TYPE_VFIELD (t);
4645 if (vfield != NULL_TREE
4646 && DECL_FIELD_CONTEXT (vfield) != t)
4648 tree binfo = get_binfo (DECL_FIELD_CONTEXT (vfield), t, 0);
4649 tree offset = BINFO_OFFSET (binfo);
4651 vfield = copy_node (vfield);
4652 copy_lang_decl (vfield);
4654 if (! integer_zerop (offset))
4655 offset = size_binop (MULT_EXPR, offset, size_int (BITS_PER_UNIT));
4656 DECL_FIELD_CONTEXT (vfield) = t;
4657 DECL_CLASS_CONTEXT (vfield) = t;
4658 DECL_FIELD_BITPOS (vfield)
4659 = size_binop (PLUS_EXPR, offset, DECL_FIELD_BITPOS (vfield));
4660 TYPE_VFIELD (t) = vfield;
4663 if (flag_rtti && TYPE_POLYMORPHIC_P (t) && !pending_hard_virtuals)
4664 modify_all_vtables (t, NULL_TREE);
4666 for (pending_hard_virtuals = nreverse (pending_hard_virtuals);
4667 pending_hard_virtuals;
4668 pending_hard_virtuals = TREE_CHAIN (pending_hard_virtuals))
4669 modify_all_vtables (t, TREE_VALUE (pending_hard_virtuals));
4671 if (TYPE_USES_VIRTUAL_BASECLASSES (t))
4674 /* Now fixup any virtual function entries from virtual bases
4675 that have different deltas. This has to come after we do the
4676 pending hard virtuals, as we might have a function that comes
4677 from multiple virtual base instances that is only overridden
4678 by a hard virtual above. */
4679 vbases = CLASSTYPE_VBASECLASSES (t);
4684 /* We might be able to shorten the amount of work we do by
4685 only doing this for vtables that come from virtual bases
4686 that have differing offsets, but don't want to miss any
4688 vbase = find_vbase_instance (BINFO_TYPE (vbases), t);
4689 dfs_walk (vbase, dfs_fixup_vtable_deltas, dfs_skip_vbases, t);
4690 vbases = TREE_CHAIN (vbases);
4694 /* Under our model of GC, every C++ class gets its own virtual
4695 function table, at least virtually. */
4696 if (pending_virtuals)
4698 pending_virtuals = nreverse (pending_virtuals);
4699 /* We must enter these virtuals into the table. */
4700 if (!CLASSTYPE_HAS_PRIMARY_BASE_P (t))
4702 if (! CLASSTYPE_COM_INTERFACE (t))
4704 /* The second slot is for the tdesc pointer when thunks are used. */
4705 if (flag_vtable_thunks)
4706 pending_virtuals = tree_cons (NULL_TREE, NULL_TREE, pending_virtuals);
4708 /* The first slot is for the rtti offset. */
4709 pending_virtuals = tree_cons (NULL_TREE, NULL_TREE, pending_virtuals);
4711 set_rtti_entry (pending_virtuals,
4712 convert (ssizetype, integer_zero_node), t);
4714 build_vtable (NULL_TREE, t);
4716 else if (! BINFO_NEW_VTABLE_MARKED (TYPE_BINFO (t)))
4717 /* Here we know enough to change the type of our virtual
4718 function table, but we will wait until later this function. */
4719 build_vtable (CLASSTYPE_PRIMARY_BINFO (t), t);
4721 /* If this type has basetypes with constructors, then those
4722 constructors might clobber the virtual function table. But
4723 they don't if the derived class shares the exact vtable of the base
4726 CLASSTYPE_NEEDS_VIRTUAL_REINIT (t) = 1;
4728 else if (CLASSTYPE_HAS_PRIMARY_BASE_P (t))
4730 tree binfo = CLASSTYPE_PRIMARY_BINFO (t);
4732 /* This class contributes nothing new to the virtual function
4733 table. However, it may have declared functions which
4734 went into the virtual function table "inherited" from the
4735 base class. If so, we grab a copy of those updated functions,
4736 and pretend they are ours. */
4738 /* See if we should steal the virtual info from base class. */
4739 if (TYPE_BINFO_VTABLE (t) == NULL_TREE)
4740 TYPE_BINFO_VTABLE (t) = BINFO_VTABLE (binfo);
4741 if (TYPE_BINFO_VIRTUALS (t) == NULL_TREE)
4742 TYPE_BINFO_VIRTUALS (t) = BINFO_VIRTUALS (binfo);
4743 if (TYPE_BINFO_VTABLE (t) != BINFO_VTABLE (binfo))
4744 CLASSTYPE_NEEDS_VIRTUAL_REINIT (t) = 1;
4747 if (TYPE_POLYMORPHIC_P (t))
4749 CLASSTYPE_VSIZE (t) = has_virtual;
4750 if (CLASSTYPE_HAS_PRIMARY_BASE_P (t))
4752 if (pending_virtuals)
4753 TYPE_BINFO_VIRTUALS (t) = chainon (TYPE_BINFO_VIRTUALS (t),
4756 else if (has_virtual)
4758 TYPE_BINFO_VIRTUALS (t) = pending_virtuals;
4759 DECL_VIRTUAL_P (TYPE_BINFO_VTABLE (t)) = 1;
4763 /* Now lay out the virtual function table. */
4766 /* Use size_int so values are memoized in common cases. */
4767 tree itype = build_index_type (size_int (has_virtual));
4768 tree atype = build_cplus_array_type (vtable_entry_type, itype);
4770 layout_type (atype);
4772 /* We may have to grow the vtable. */
4773 if (TREE_TYPE (TYPE_BINFO_VTABLE (t)) != atype)
4775 TREE_TYPE (TYPE_BINFO_VTABLE (t)) = atype;
4776 DECL_SIZE (TYPE_BINFO_VTABLE (t)) = 0;
4777 layout_decl (TYPE_BINFO_VTABLE (t), 0);
4778 /* At one time the vtable info was grabbed 2 words at a time. This
4779 fails on sparc unless you have 8-byte alignment. (tiemann) */
4780 DECL_ALIGN (TYPE_BINFO_VTABLE (t))
4781 = MAX (TYPE_ALIGN (double_type_node),
4782 DECL_ALIGN (TYPE_BINFO_VTABLE (t)));
4786 /* If we created a new vtbl pointer for this class, add it to the
4788 if (TYPE_VFIELD (t) && CLASSTYPE_VFIELD_PARENT (t) == -1)
4789 CLASSTYPE_VFIELDS (t)
4790 = chainon (CLASSTYPE_VFIELDS (t), build_tree_list (NULL_TREE, t));
4792 finish_struct_bits (t);
4794 /* Complete the rtl for any static member objects of the type we're
4796 for (x = TYPE_FIELDS (t); x; x = TREE_CHAIN (x))
4798 if (TREE_CODE (x) == VAR_DECL && TREE_STATIC (x)
4799 && TREE_TYPE (x) == t)
4801 DECL_MODE (x) = TYPE_MODE (t);
4802 make_decl_rtl (x, NULL, 0);
4806 /* Done with FIELDS...now decide whether to sort these for
4807 faster lookups later.
4809 The C front-end only does this when n_fields > 15. We use
4810 a smaller number because most searches fail (succeeding
4811 ultimately as the search bores through the inheritance
4812 hierarchy), and we want this failure to occur quickly. */
4814 n_fields = count_fields (TYPE_FIELDS (t));
4817 tree field_vec = make_tree_vec (n_fields);
4818 add_fields_to_vec (TYPE_FIELDS (t), field_vec, 0);
4819 qsort (&TREE_VEC_ELT (field_vec, 0), n_fields, sizeof (tree),
4820 (int (*)(const void *, const void *))field_decl_cmp);
4821 if (! DECL_LANG_SPECIFIC (TYPE_MAIN_DECL (t)))
4822 retrofit_lang_decl (TYPE_MAIN_DECL (t));
4823 DECL_SORTED_FIELDS (TYPE_MAIN_DECL (t)) = field_vec;
4826 if (TYPE_HAS_CONSTRUCTOR (t))
4828 tree vfields = CLASSTYPE_VFIELDS (t);
4832 /* Mark the fact that constructor for T
4833 could affect anybody inheriting from T
4834 who wants to initialize vtables for VFIELDS's type. */
4835 if (VF_DERIVED_VALUE (vfields))
4836 TREE_ADDRESSABLE (vfields) = 1;
4837 vfields = TREE_CHAIN (vfields);
4841 if (CLASSTYPE_VSIZE (t) != 0)
4843 /* In addition to this one, all the other vfields should be listed. */
4844 /* Before that can be done, we have to have FIELD_DECLs for them, and
4845 a place to find them. */
4846 TYPE_NONCOPIED_PARTS (t)
4847 = tree_cons (default_conversion (TYPE_BINFO_VTABLE (t)),
4848 TYPE_VFIELD (t), TYPE_NONCOPIED_PARTS (t));
4850 if (warn_nonvdtor && TYPE_HAS_DESTRUCTOR (t)
4851 && DECL_VINDEX (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (t), 1)) == NULL_TREE)
4852 cp_warning ("`%#T' has virtual functions but non-virtual destructor",
4856 /* Make the rtl for any new vtables we have created, and unmark
4857 the base types we marked. */
4859 hack_incomplete_structures (t);
4861 if (warn_overloaded_virtual)
4864 maybe_suppress_debug_info (t);
4866 /* Finish debugging output for this type. */
4867 rest_of_type_compilation (t, toplevel_bindings_p ());
4870 /* When T was built up, the member declarations were added in reverse
4871 order. Rearrange them to declaration order. */
4874 unreverse_member_declarations (t)
4881 /* The TYPE_FIELDS, TYPE_METHODS, and CLASSTYPE_TAGS are all in
4882 reverse order. Put them in declaration order now. */
4883 TYPE_METHODS (t) = nreverse (TYPE_METHODS (t));
4884 CLASSTYPE_TAGS (t) = nreverse (CLASSTYPE_TAGS (t));
4886 /* Actually, for the TYPE_FIELDS, only the non TYPE_DECLs are in
4887 reverse order, so we can't just use nreverse. */
4889 for (x = TYPE_FIELDS (t);
4890 x && TREE_CODE (x) != TYPE_DECL;
4893 next = TREE_CHAIN (x);
4894 TREE_CHAIN (x) = prev;
4899 TREE_CHAIN (TYPE_FIELDS (t)) = x;
4901 TYPE_FIELDS (t) = prev;
4906 finish_struct (t, attributes)
4909 /* Now that we've got all the field declarations, reverse everything
4911 unreverse_member_declarations (t);
4913 cplus_decl_attributes (t, attributes, NULL_TREE);
4915 if (processing_template_decl)
4917 finish_struct_methods (t);
4918 TYPE_SIZE (t) = integer_zero_node;
4921 finish_struct_1 (t);
4923 TYPE_BEING_DEFINED (t) = 0;
4925 if (current_class_type)
4928 error ("trying to finish struct, but kicked out due to previous parse errors.");
4930 if (processing_template_decl)
4932 tree scope = current_scope ();
4933 if (scope && TREE_CODE (scope) == FUNCTION_DECL)
4934 add_tree (build_min (TAG_DEFN, t));
4940 /* Return the dynamic type of INSTANCE, if known.
4941 Used to determine whether the virtual function table is needed
4944 *NONNULL is set iff INSTANCE can be known to be nonnull, regardless
4945 of our knowledge of its type. */
4948 fixed_type_or_null (instance, nonnull)
4955 switch (TREE_CODE (instance))
4958 /* Check that we are not going through a cast of some sort. */
4959 if (TREE_TYPE (instance)
4960 == TREE_TYPE (TREE_TYPE (TREE_OPERAND (instance, 0))))
4961 instance = TREE_OPERAND (instance, 0);
4962 /* fall through... */
4964 /* This is a call to a constructor, hence it's never zero. */
4965 if (TREE_HAS_CONSTRUCTOR (instance))
4969 return TREE_TYPE (instance);
4974 /* This is a call to a constructor, hence it's never zero. */
4975 if (TREE_HAS_CONSTRUCTOR (instance))
4979 return TREE_TYPE (instance);
4981 return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull);
4988 if (TREE_CODE (TREE_OPERAND (instance, 1)) == INTEGER_CST)
4989 /* Propagate nonnull. */
4990 fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull);
4991 if (TREE_CODE (TREE_OPERAND (instance, 0)) == ADDR_EXPR)
4992 return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull);
4997 return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull);
5002 return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull);
5005 return fixed_type_or_null (TREE_OPERAND (instance, 1), nonnull);
5009 if (TREE_CODE (TREE_TYPE (instance)) == ARRAY_TYPE
5010 && IS_AGGR_TYPE (TREE_TYPE (TREE_TYPE (instance))))
5014 return TREE_TYPE (TREE_TYPE (instance));
5016 /* fall through... */
5019 if (IS_AGGR_TYPE (TREE_TYPE (instance)))
5023 return TREE_TYPE (instance);
5027 if (instance == current_class_ptr
5028 && flag_this_is_variable <= 0)
5030 /* Normally, 'this' must be non-null. */
5031 if (flag_this_is_variable == 0)
5034 /* <0 means we're in a constructor and we know our type. */
5035 if (flag_this_is_variable < 0)
5036 return TREE_TYPE (TREE_TYPE (instance));
5038 else if (TREE_CODE (TREE_TYPE (instance)) == REFERENCE_TYPE)
5039 /* Reference variables should be references to objects. */
5049 /* Return non-zero if the dynamic type of INSTANCE is known, and equivalent
5050 to the static type. We also handle the case where INSTANCE is really
5053 Used to determine whether the virtual function table is needed
5056 *NONNULL is set iff INSTANCE can be known to be nonnull, regardless
5057 of our knowledge of its type. */
5060 resolves_to_fixed_type_p (instance, nonnull)
5064 tree t = TREE_TYPE (instance);
5065 tree fixed = fixed_type_or_null (instance, nonnull);
5066 if (fixed == NULL_TREE)
5068 if (POINTER_TYPE_P (t))
5070 return same_type_p (TYPE_MAIN_VARIANT (t), TYPE_MAIN_VARIANT (fixed));
5075 init_class_processing ()
5077 current_class_depth = 0;
5078 current_class_stack_size = 10;
5080 = (class_stack_node_t) xmalloc (current_class_stack_size
5081 * sizeof (struct class_stack_node));
5083 access_default_node = build_int_2 (0, 0);
5084 access_public_node = build_int_2 (1, 0);
5085 access_protected_node = build_int_2 (2, 0);
5086 access_private_node = build_int_2 (3, 0);
5087 access_default_virtual_node = build_int_2 (4, 0);
5088 access_public_virtual_node = build_int_2 (5, 0);
5089 access_protected_virtual_node = build_int_2 (6, 0);
5090 access_private_virtual_node = build_int_2 (7, 0);
5093 /* Set current scope to NAME. CODE tells us if this is a
5094 STRUCT, UNION, or ENUM environment.
5096 NAME may end up being NULL_TREE if this is an anonymous or
5097 late-bound struct (as in "struct { ... } foo;") */
5099 /* Set global variables CURRENT_CLASS_NAME and CURRENT_CLASS_TYPE to
5100 appropriate values, found by looking up the type definition of
5103 If MODIFY is 1, we set IDENTIFIER_CLASS_VALUE's of names
5104 which can be seen locally to the class. They are shadowed by
5105 any subsequent local declaration (including parameter names).
5107 If MODIFY is 2, we set IDENTIFIER_CLASS_VALUE's of names
5108 which have static meaning (i.e., static members, static
5109 member functions, enum declarations, etc).
5111 If MODIFY is 3, we set IDENTIFIER_CLASS_VALUE of names
5112 which can be seen locally to the class (as in 1), but
5113 know that we are doing this for declaration purposes
5114 (i.e. friend foo::bar (int)).
5116 So that we may avoid calls to lookup_name, we cache the _TYPE
5117 nodes of local TYPE_DECLs in the TREE_TYPE field of the name.
5119 For multiple inheritance, we perform a two-pass depth-first search
5120 of the type lattice. The first pass performs a pre-order search,
5121 marking types after the type has had its fields installed in
5122 the appropriate IDENTIFIER_CLASS_VALUE slot. The second pass merely
5123 unmarks the marked types. If a field or member function name
5124 appears in an ambiguous way, the IDENTIFIER_CLASS_VALUE of
5125 that name becomes `error_mark_node'. */
5128 pushclass (type, modify)
5132 type = TYPE_MAIN_VARIANT (type);
5134 /* Make sure there is enough room for the new entry on the stack. */
5135 if (current_class_depth + 1 >= current_class_stack_size)
5137 current_class_stack_size *= 2;
5139 = (class_stack_node_t) xrealloc (current_class_stack,
5140 current_class_stack_size
5141 * sizeof (struct class_stack_node));
5144 /* Insert a new entry on the class stack. */
5145 current_class_stack[current_class_depth].name = current_class_name;
5146 current_class_stack[current_class_depth].type = current_class_type;
5147 current_class_stack[current_class_depth].access = current_access_specifier;
5148 current_class_stack[current_class_depth].names_used = 0;
5149 current_class_depth++;
5151 /* Now set up the new type. */
5152 current_class_name = TYPE_NAME (type);
5153 if (TREE_CODE (current_class_name) == TYPE_DECL)
5154 current_class_name = DECL_NAME (current_class_name);
5155 current_class_type = type;
5157 /* By default, things in classes are private, while things in
5158 structures or unions are public. */
5159 current_access_specifier = (CLASSTYPE_DECLARED_CLASS (type)
5160 ? access_private_node
5161 : access_public_node);
5163 if (previous_class_type != NULL_TREE
5164 && (type != previous_class_type
5165 || TYPE_SIZE (previous_class_type) == NULL_TREE)
5166 && current_class_depth == 1)
5168 /* Forcibly remove any old class remnants. */
5169 invalidate_class_lookup_cache ();
5172 /* If we're about to enter a nested class, clear
5173 IDENTIFIER_CLASS_VALUE for the enclosing classes. */
5174 if (modify && current_class_depth > 1)
5175 clear_identifier_class_values ();
5180 if (CLASSTYPE_TEMPLATE_INFO (type))
5181 overload_template_name (type);
5186 if (type != previous_class_type || current_class_depth > 1)
5187 push_class_decls (type);
5192 /* We are re-entering the same class we just left, so we
5193 don't have to search the whole inheritance matrix to find
5194 all the decls to bind again. Instead, we install the
5195 cached class_shadowed list, and walk through it binding
5196 names and setting up IDENTIFIER_TYPE_VALUEs. */
5197 set_class_shadows (previous_class_values);
5198 for (item = previous_class_values; item; item = TREE_CHAIN (item))
5200 tree id = TREE_PURPOSE (item);
5201 tree decl = TREE_TYPE (item);
5203 push_class_binding (id, decl);
5204 if (TREE_CODE (decl) == TYPE_DECL)
5205 set_identifier_type_value (id, TREE_TYPE (decl));
5207 unuse_fields (type);
5210 storetags (CLASSTYPE_TAGS (type));
5214 /* When we exit a toplevel class scope, we save the
5215 IDENTIFIER_CLASS_VALUEs so that we can restore them quickly if we
5216 reenter the class. Here, we've entered some other class, so we
5217 must invalidate our cache. */
5220 invalidate_class_lookup_cache ()
5224 /* This code can be seen as a cache miss. When we've cached a
5225 class' scope's bindings and we can't use them, we need to reset
5226 them. This is it! */
5227 for (t = previous_class_values; t; t = TREE_CHAIN (t))
5228 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (t)) = NULL_TREE;
5230 previous_class_type = NULL_TREE;
5233 /* Get out of the current class scope. If we were in a class scope
5234 previously, that is the one popped to. */
5240 /* Since poplevel_class does the popping of class decls nowadays,
5241 this really only frees the obstack used for these decls. */
5244 current_class_depth--;
5245 current_class_name = current_class_stack[current_class_depth].name;
5246 current_class_type = current_class_stack[current_class_depth].type;
5247 current_access_specifier = current_class_stack[current_class_depth].access;
5248 if (current_class_stack[current_class_depth].names_used)
5249 splay_tree_delete (current_class_stack[current_class_depth].names_used);
5252 /* Returns 1 if current_class_type is either T or a nested type of T. */
5255 currently_open_class (t)
5259 if (t == current_class_type)
5261 for (i = 0; i < current_class_depth; ++i)
5262 if (current_class_stack [i].type == t)
5267 /* When entering a class scope, all enclosing class scopes' names with
5268 static meaning (static variables, static functions, types and enumerators)
5269 have to be visible. This recursive function calls pushclass for all
5270 enclosing class contexts until global or a local scope is reached.
5271 TYPE is the enclosed class and MODIFY is equivalent with the pushclass
5272 formal of the same name. */
5275 push_nested_class (type, modify)
5281 /* A namespace might be passed in error cases, like A::B:C. */
5282 if (type == NULL_TREE
5283 || type == error_mark_node
5284 || TREE_CODE (type) == NAMESPACE_DECL
5285 || ! IS_AGGR_TYPE (type)
5286 || TREE_CODE (type) == TEMPLATE_TYPE_PARM
5287 || TREE_CODE (type) == TEMPLATE_TEMPLATE_PARM)
5290 context = DECL_CONTEXT (TYPE_MAIN_DECL (type));
5292 if (context && CLASS_TYPE_P (context))
5293 push_nested_class (context, 2);
5294 pushclass (type, modify);
5297 /* Undoes a push_nested_class call. MODIFY is passed on to popclass. */
5302 tree context = DECL_CONTEXT (TYPE_MAIN_DECL (current_class_type));
5305 if (context && CLASS_TYPE_P (context))
5306 pop_nested_class ();
5309 /* Set global variables CURRENT_LANG_NAME to appropriate value
5310 so that behavior of name-mangling machinery is correct. */
5313 push_lang_context (name)
5316 *current_lang_stack++ = current_lang_name;
5317 if (current_lang_stack - &VARRAY_TREE (current_lang_base, 0)
5318 >= (ptrdiff_t) VARRAY_SIZE (current_lang_base))
5320 size_t old_size = VARRAY_SIZE (current_lang_base);
5322 VARRAY_GROW (current_lang_base, old_size + 10);
5323 current_lang_stack = &VARRAY_TREE (current_lang_base, old_size);
5326 if (name == lang_name_cplusplus)
5328 strict_prototype = strict_prototypes_lang_cplusplus;
5329 current_lang_name = name;
5331 else if (name == lang_name_java)
5333 strict_prototype = strict_prototypes_lang_cplusplus;
5334 current_lang_name = name;
5335 /* DECL_IGNORED_P is initially set for these types, to avoid clutter.
5336 (See record_builtin_java_type in decl.c.) However, that causes
5337 incorrect debug entries if these types are actually used.
5338 So we re-enable debug output after extern "Java". */
5339 DECL_IGNORED_P (java_byte_type_node) = 0;
5340 DECL_IGNORED_P (java_short_type_node) = 0;
5341 DECL_IGNORED_P (java_int_type_node) = 0;
5342 DECL_IGNORED_P (java_long_type_node) = 0;
5343 DECL_IGNORED_P (java_float_type_node) = 0;
5344 DECL_IGNORED_P (java_double_type_node) = 0;
5345 DECL_IGNORED_P (java_char_type_node) = 0;
5346 DECL_IGNORED_P (java_boolean_type_node) = 0;
5348 else if (name == lang_name_c)
5350 strict_prototype = strict_prototypes_lang_c;
5351 current_lang_name = name;
5354 error ("language string `\"%s\"' not recognized", IDENTIFIER_POINTER (name));
5357 /* Get out of the current language scope. */
5362 /* Clear the current entry so that garbage collector won't hold on
5364 *current_lang_stack = NULL_TREE;
5365 current_lang_name = *--current_lang_stack;
5366 if (current_lang_name == lang_name_cplusplus
5367 || current_lang_name == lang_name_java)
5368 strict_prototype = strict_prototypes_lang_cplusplus;
5369 else if (current_lang_name == lang_name_c)
5370 strict_prototype = strict_prototypes_lang_c;
5373 /* Type instantiation routines. */
5375 /* Given an OVERLOAD and a TARGET_TYPE, return the function that
5376 matches the TARGET_TYPE. If there is no satisfactory match, return
5377 error_mark_node, and issue an error message if COMPLAIN is
5378 non-zero. If TEMPLATE_ONLY, the name of the overloaded function
5379 was a template-id, and EXPLICIT_TARGS are the explicitly provided
5380 template arguments. */
5383 resolve_address_of_overloaded_function (target_type,
5392 tree explicit_targs;
5394 /* Here's what the standard says:
5398 If the name is a function template, template argument deduction
5399 is done, and if the argument deduction succeeds, the deduced
5400 arguments are used to generate a single template function, which
5401 is added to the set of overloaded functions considered.
5403 Non-member functions and static member functions match targets of
5404 type "pointer-to-function" or "reference-to-function." Nonstatic
5405 member functions match targets of type "pointer-to-member
5406 function;" the function type of the pointer to member is used to
5407 select the member function from the set of overloaded member
5408 functions. If a nonstatic member function is selected, the
5409 reference to the overloaded function name is required to have the
5410 form of a pointer to member as described in 5.3.1.
5412 If more than one function is selected, any template functions in
5413 the set are eliminated if the set also contains a non-template
5414 function, and any given template function is eliminated if the
5415 set contains a second template function that is more specialized
5416 than the first according to the partial ordering rules 14.5.5.2.
5417 After such eliminations, if any, there shall remain exactly one
5418 selected function. */
5421 int is_reference = 0;
5422 /* We store the matches in a TREE_LIST rooted here. The functions
5423 are the TREE_PURPOSE, not the TREE_VALUE, in this list, for easy
5424 interoperability with most_specialized_instantiation. */
5425 tree matches = NULL_TREE;
5428 /* By the time we get here, we should be seeing only real
5429 pointer-to-member types, not the internal POINTER_TYPE to
5430 METHOD_TYPE representation. */
5431 my_friendly_assert (!(TREE_CODE (target_type) == POINTER_TYPE
5432 && (TREE_CODE (TREE_TYPE (target_type))
5433 == METHOD_TYPE)), 0);
5435 /* Check that the TARGET_TYPE is reasonable. */
5436 if (TYPE_PTRFN_P (target_type))
5439 else if (TYPE_PTRMEMFUNC_P (target_type))
5440 /* This is OK, too. */
5442 else if (TREE_CODE (target_type) == FUNCTION_TYPE)
5444 /* This is OK, too. This comes from a conversion to reference
5446 target_type = build_reference_type (target_type);
5452 cp_error("cannot resolve overloaded function `%D' based on conversion to type `%T'",
5453 DECL_NAME (OVL_FUNCTION (overload)), target_type);
5454 return error_mark_node;
5457 /* If we can find a non-template function that matches, we can just
5458 use it. There's no point in generating template instantiations
5459 if we're just going to throw them out anyhow. But, of course, we
5460 can only do this when we don't *need* a template function. */
5465 for (fns = overload; fns; fns = OVL_CHAIN (fns))
5467 tree fn = OVL_FUNCTION (fns);
5470 if (TREE_CODE (fn) == TEMPLATE_DECL)
5471 /* We're not looking for templates just yet. */
5474 if ((TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE)
5476 /* We're looking for a non-static member, and this isn't
5477 one, or vice versa. */
5480 /* See if there's a match. */
5481 fntype = TREE_TYPE (fn);
5483 fntype = build_ptrmemfunc_type (build_pointer_type (fntype));
5484 else if (!is_reference)
5485 fntype = build_pointer_type (fntype);
5487 if (can_convert_arg (target_type, fntype, fn))
5488 matches = tree_cons (fn, NULL_TREE, matches);
5492 /* Now, if we've already got a match (or matches), there's no need
5493 to proceed to the template functions. But, if we don't have a
5494 match we need to look at them, too. */
5497 tree target_fn_type;
5498 tree target_arg_types;
5503 = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (target_type));
5505 target_fn_type = TREE_TYPE (target_type);
5506 target_arg_types = TYPE_ARG_TYPES (target_fn_type);
5508 for (fns = overload; fns; fns = OVL_CHAIN (fns))
5510 tree fn = OVL_FUNCTION (fns);
5512 tree instantiation_type;
5515 if (TREE_CODE (fn) != TEMPLATE_DECL)
5516 /* We're only looking for templates. */
5519 if ((TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE)
5521 /* We're not looking for a non-static member, and this is
5522 one, or vice versa. */
5525 /* Try to do argument deduction. */
5526 targs = make_tree_vec (DECL_NTPARMS (fn));
5527 if (fn_type_unification (fn, explicit_targs, targs,
5528 target_arg_types, NULL_TREE,
5530 /* Argument deduction failed. */
5533 /* Instantiate the template. */
5534 instantiation = instantiate_template (fn, targs);
5535 if (instantiation == error_mark_node)
5536 /* Instantiation failed. */
5539 /* See if there's a match. */
5540 instantiation_type = TREE_TYPE (instantiation);
5542 instantiation_type =
5543 build_ptrmemfunc_type (build_pointer_type (instantiation_type));
5544 else if (!is_reference)
5545 instantiation_type = build_pointer_type (instantiation_type);
5546 if (can_convert_arg (target_type, instantiation_type, instantiation))
5547 matches = tree_cons (instantiation, fn, matches);
5550 /* Now, remove all but the most specialized of the matches. */
5553 tree match = most_specialized_instantiation (matches,
5556 if (match != error_mark_node)
5557 matches = tree_cons (match, NULL_TREE, NULL_TREE);
5561 /* Now we should have exactly one function in MATCHES. */
5562 if (matches == NULL_TREE)
5564 /* There were *no* matches. */
5567 cp_error ("no matches converting function `%D' to type `%#T'",
5568 DECL_NAME (OVL_FUNCTION (overload)),
5571 /* print_candidates expects a chain with the functions in
5572 TREE_VALUE slots, so we cons one up here (we're losing anyway,
5573 so why be clever?). */
5574 for (; overload; overload = OVL_NEXT (overload))
5575 matches = tree_cons (NULL_TREE, OVL_CURRENT (overload),
5578 print_candidates (matches);
5580 return error_mark_node;
5582 else if (TREE_CHAIN (matches))
5584 /* There were too many matches. */
5590 cp_error ("converting overloaded function `%D' to type `%#T' is ambiguous",
5591 DECL_NAME (OVL_FUNCTION (overload)),
5594 /* Since print_candidates expects the functions in the
5595 TREE_VALUE slot, we flip them here. */
5596 for (match = matches; match; match = TREE_CHAIN (match))
5597 TREE_VALUE (match) = TREE_PURPOSE (match);
5599 print_candidates (matches);
5602 return error_mark_node;
5605 /* Good, exactly one match. Now, convert it to the correct type. */
5606 fn = TREE_PURPOSE (matches);
5610 if (TYPE_PTRFN_P (target_type) || TYPE_PTRMEMFUNC_P (target_type))
5611 return build_unary_op (ADDR_EXPR, fn, 0);
5614 /* The target must be a REFERENCE_TYPE. Above, build_unary_op
5615 will mark the function as addressed, but here we must do it
5617 mark_addressable (fn);
5623 /* This function will instantiate the type of the expression given in
5624 RHS to match the type of LHSTYPE. If errors exist, then return
5625 error_mark_node. We only complain is COMPLAIN is set. If we are
5626 not complaining, never modify rhs, as overload resolution wants to
5627 try many possible instantiations, in hopes that at least one will
5630 FLAGS is a bitmask, as we see at the top of the function.
5632 For non-recursive calls, LHSTYPE should be a function, pointer to
5633 function, or a pointer to member function. */
5636 instantiate_type (lhstype, rhs, flags)
5640 int complain = (flags & 1);
5641 int strict = (flags & 2) ? COMPARE_NO_ATTRIBUTES : COMPARE_STRICT;
5643 if (TREE_CODE (lhstype) == UNKNOWN_TYPE)
5646 error ("not enough type information");
5647 return error_mark_node;
5650 if (TREE_TYPE (rhs) != NULL_TREE && ! (type_unknown_p (rhs)))
5652 if (comptypes (lhstype, TREE_TYPE (rhs), strict))
5655 cp_error ("argument of type `%T' does not match `%T'",
5656 TREE_TYPE (rhs), lhstype);
5657 return error_mark_node;
5660 /* We don't overwrite rhs if it is an overloaded function.
5661 Copying it would destroy the tree link. */
5662 if (TREE_CODE (rhs) != OVERLOAD)
5663 rhs = copy_node (rhs);
5665 /* This should really only be used when attempting to distinguish
5666 what sort of a pointer to function we have. For now, any
5667 arithmetic operation which is not supported on pointers
5668 is rejected as an error. */
5670 switch (TREE_CODE (rhs))
5677 my_friendly_abort (177);
5678 return error_mark_node;
5685 new_rhs = instantiate_type (build_pointer_type (lhstype),
5686 TREE_OPERAND (rhs, 0), flags);
5687 if (new_rhs == error_mark_node)
5688 return error_mark_node;
5690 TREE_TYPE (rhs) = lhstype;
5691 TREE_OPERAND (rhs, 0) = new_rhs;
5696 rhs = copy_node (TREE_OPERAND (rhs, 0));
5697 TREE_TYPE (rhs) = unknown_type_node;
5698 return instantiate_type (lhstype, rhs, flags);
5702 tree r = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), flags);
5704 if (r != error_mark_node && TYPE_PTRMEMFUNC_P (lhstype)
5705 && complain && !flag_ms_extensions)
5707 /* Note: we check this after the recursive call to avoid
5708 complaining about cases where overload resolution fails. */
5710 tree t = TREE_TYPE (TREE_OPERAND (rhs, 0));
5711 tree fn = PTRMEM_CST_MEMBER (r);
5713 my_friendly_assert (TREE_CODE (r) == PTRMEM_CST, 990811);
5716 ("object-dependent reference to `%E' can only be used in a call",
5719 (" to form a pointer to member function, say `&%T::%E'",
5727 rhs = TREE_OPERAND (rhs, 1);
5728 if (BASELINK_P (rhs))
5729 return instantiate_type (lhstype, TREE_VALUE (rhs), flags);
5731 /* This can happen if we are forming a pointer-to-member for a
5733 my_friendly_assert (TREE_CODE (rhs) == TEMPLATE_ID_EXPR, 0);
5737 case TEMPLATE_ID_EXPR:
5739 resolve_address_of_overloaded_function (lhstype,
5740 TREE_OPERAND (rhs, 0),
5742 /*template_only=*/1,
5743 TREE_OPERAND (rhs, 1));
5747 resolve_address_of_overloaded_function (lhstype,
5750 /*template_only=*/0,
5751 /*explicit_targs=*/NULL_TREE);
5754 /* Now we should have a baselink. */
5755 my_friendly_assert (BASELINK_P (rhs), 990412);
5757 return instantiate_type (lhstype, TREE_VALUE (rhs), flags);
5760 /* This is too hard for now. */
5761 my_friendly_abort (183);
5762 return error_mark_node;
5767 TREE_OPERAND (rhs, 0)
5768 = instantiate_type (lhstype, TREE_OPERAND (rhs, 0), flags);
5769 if (TREE_OPERAND (rhs, 0) == error_mark_node)
5770 return error_mark_node;
5771 TREE_OPERAND (rhs, 1)
5772 = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), flags);
5773 if (TREE_OPERAND (rhs, 1) == error_mark_node)
5774 return error_mark_node;
5776 TREE_TYPE (rhs) = lhstype;
5780 case TRUNC_DIV_EXPR:
5781 case FLOOR_DIV_EXPR:
5783 case ROUND_DIV_EXPR:
5785 case TRUNC_MOD_EXPR:
5786 case FLOOR_MOD_EXPR:
5788 case ROUND_MOD_EXPR:
5789 case FIX_ROUND_EXPR:
5790 case FIX_FLOOR_EXPR:
5792 case FIX_TRUNC_EXPR:
5808 case PREINCREMENT_EXPR:
5809 case PREDECREMENT_EXPR:
5810 case POSTINCREMENT_EXPR:
5811 case POSTDECREMENT_EXPR:
5813 error ("invalid operation on uninstantiated type");
5814 return error_mark_node;
5816 case TRUTH_AND_EXPR:
5818 case TRUTH_XOR_EXPR:
5825 case TRUTH_ANDIF_EXPR:
5826 case TRUTH_ORIF_EXPR:
5827 case TRUTH_NOT_EXPR:
5829 error ("not enough type information");
5830 return error_mark_node;
5833 if (type_unknown_p (TREE_OPERAND (rhs, 0)))
5836 error ("not enough type information");
5837 return error_mark_node;
5839 TREE_OPERAND (rhs, 1)
5840 = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), flags);
5841 if (TREE_OPERAND (rhs, 1) == error_mark_node)
5842 return error_mark_node;
5843 TREE_OPERAND (rhs, 2)
5844 = instantiate_type (lhstype, TREE_OPERAND (rhs, 2), flags);
5845 if (TREE_OPERAND (rhs, 2) == error_mark_node)
5846 return error_mark_node;
5848 TREE_TYPE (rhs) = lhstype;
5852 TREE_OPERAND (rhs, 1)
5853 = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), flags);
5854 if (TREE_OPERAND (rhs, 1) == error_mark_node)
5855 return error_mark_node;
5857 TREE_TYPE (rhs) = lhstype;
5861 return instantiate_type (lhstype, TREE_OPERAND (rhs, 0), flags);
5863 case ENTRY_VALUE_EXPR:
5864 my_friendly_abort (184);
5865 return error_mark_node;
5868 return error_mark_node;
5871 my_friendly_abort (185);
5872 return error_mark_node;
5876 /* Return the name of the virtual function pointer field
5877 (as an IDENTIFIER_NODE) for the given TYPE. Note that
5878 this may have to look back through base types to find the
5879 ultimate field name. (For single inheritance, these could
5880 all be the same name. Who knows for multiple inheritance). */
5883 get_vfield_name (type)
5886 tree binfo = TYPE_BINFO (type);
5889 while (BINFO_BASETYPES (binfo)
5890 && TYPE_POLYMORPHIC_P (BINFO_TYPE (BINFO_BASETYPE (binfo, 0)))
5891 && ! TREE_VIA_VIRTUAL (BINFO_BASETYPE (binfo, 0)))
5892 binfo = BINFO_BASETYPE (binfo, 0);
5894 type = BINFO_TYPE (binfo);
5895 buf = (char *) alloca (sizeof (VFIELD_NAME_FORMAT)
5896 + TYPE_NAME_LENGTH (type) + 2);
5897 sprintf (buf, VFIELD_NAME_FORMAT, TYPE_NAME_STRING (type));
5898 return get_identifier (buf);
5902 print_class_statistics ()
5904 #ifdef GATHER_STATISTICS
5905 fprintf (stderr, "convert_harshness = %d\n", n_convert_harshness);
5906 fprintf (stderr, "compute_conversion_costs = %d\n", n_compute_conversion_costs);
5907 fprintf (stderr, "build_method_call = %d (inner = %d)\n",
5908 n_build_method_call, n_inner_fields_searched);
5911 fprintf (stderr, "vtables = %d; vtable searches = %d\n",
5912 n_vtables, n_vtable_searches);
5913 fprintf (stderr, "vtable entries = %d; vtable elems = %d\n",
5914 n_vtable_entries, n_vtable_elems);
5919 /* Build a dummy reference to ourselves so Derived::Base (and A::A) works,
5920 according to [class]:
5921 The class-name is also inserted
5922 into the scope of the class itself. For purposes of access checking,
5923 the inserted class name is treated as if it were a public member name. */
5926 build_self_reference ()
5928 tree name = constructor_name (current_class_type);
5929 tree value = build_lang_decl (TYPE_DECL, name, current_class_type);
5932 DECL_NONLOCAL (value) = 1;
5933 DECL_CONTEXT (value) = current_class_type;
5934 DECL_CLASS_CONTEXT (value) = current_class_type;
5935 DECL_ARTIFICIAL (value) = 1;
5937 if (processing_template_decl)
5938 value = push_template_decl (value);
5940 saved_cas = current_access_specifier;
5941 current_access_specifier = access_public_node;
5942 finish_member_declaration (value);
5943 current_access_specifier = saved_cas;
5946 /* Returns 1 if TYPE contains only padding bytes. */
5949 is_empty_class (type)
5954 if (type == error_mark_node)
5957 if (! IS_AGGR_TYPE (type))
5961 return CLASSTYPE_SIZE (type) == integer_zero_node;
5963 if (TYPE_BINFO_BASETYPES (type))
5965 t = TYPE_FIELDS (type);
5966 while (t && TREE_CODE (t) != FIELD_DECL)
5968 return (t == NULL_TREE);
5971 /* Find the enclosing class of the given NODE. NODE can be a *_DECL or
5972 a *_TYPE node. NODE can also be a local class. */
5975 get_enclosing_class (type)
5980 while (node && TREE_CODE (node) != NAMESPACE_DECL)
5982 switch (TREE_CODE_CLASS (TREE_CODE (node)))
5985 node = DECL_CONTEXT (node);
5991 node = TYPE_CONTEXT (node);
5995 my_friendly_abort (0);
6001 /* Return 1 if TYPE or one of its enclosing classes is derived from BASE. */
6004 is_base_of_enclosing_class (base, type)
6009 if (get_binfo (base, type, 0))
6012 type = get_enclosing_class (type);
6017 /* Note that NAME was looked up while the current class was being
6018 defined and that the result of that lookup was DECL. */
6021 maybe_note_name_used_in_class (name, decl)
6025 splay_tree names_used;
6027 /* If we're not defining a class, there's nothing to do. */
6028 if (!current_class_type || !TYPE_BEING_DEFINED (current_class_type))
6031 /* If there's already a binding for this NAME, then we don't have
6032 anything to worry about. */
6033 if (IDENTIFIER_CLASS_VALUE (name))
6036 if (!current_class_stack[current_class_depth - 1].names_used)
6037 current_class_stack[current_class_depth - 1].names_used
6038 = splay_tree_new (splay_tree_compare_pointers, 0, 0);
6039 names_used = current_class_stack[current_class_depth - 1].names_used;
6041 splay_tree_insert (names_used,
6042 (splay_tree_key) name,
6043 (splay_tree_value) decl);
6046 /* Note that NAME was declared (as DECL) in the current class. Check
6047 to see that the declaration is legal. */
6050 note_name_declared_in_class (name, decl)
6054 splay_tree names_used;
6057 /* Look to see if we ever used this name. */
6059 = current_class_stack[current_class_depth - 1].names_used;
6063 n = splay_tree_lookup (names_used, (splay_tree_key) name);
6066 /* [basic.scope.class]
6068 A name N used in a class S shall refer to the same declaration
6069 in its context and when re-evaluated in the completed scope of
6071 cp_error ("declaration of `%#D'", decl);
6072 cp_error_at ("changes meaning of `%s' from `%+#D'",
6073 IDENTIFIER_POINTER (DECL_NAME (decl)),
6078 /* Dump the offsets of all the bases rooted at BINFO to stderr.
6079 INDENT should be zero when called from the top level; it is
6080 incremented recursively. */
6083 dump_class_hierarchy (binfo, indent)
6089 fprintf (stderr, "%*s0x%x (%s) %d %s\n", indent, "",
6090 (unsigned int) binfo,
6091 type_as_string (binfo, TS_PLAIN),
6092 TREE_INT_CST_LOW (BINFO_OFFSET (binfo)),
6093 BINFO_PRIMARY_MARKED_P (binfo) ? "primary" : "");
6095 for (i = 0; i < BINFO_N_BASETYPES (binfo); ++i)
6096 dump_class_hierarchy (BINFO_BASETYPE (binfo, i), indent + 2);