static bool check_bitfield_decl (tree);
static bool check_field_decl (tree, tree, int *, int *);
static void check_field_decls (tree, tree *, int *, int *);
-static tree *build_base_field (record_layout_info, tree, splay_tree, tree *);
static void build_base_fields (record_layout_info, splay_tree, tree *);
static void check_methods (tree);
static void remove_zero_width_bit_fields (tree);
fields at NEXT_FIELD, and return it. */
static tree
-build_base_field_1 (tree t, tree binfo, tree *&next_field)
+build_base_field_1 (tree t, tree binfo, tree access, tree *&next_field)
{
/* Create the FIELD_DECL. */
tree basetype = BINFO_TYPE (binfo);
DECL_ARTIFICIAL (decl) = 1;
DECL_IGNORED_P (decl) = 1;
DECL_FIELD_CONTEXT (decl) = t;
- TREE_PRIVATE (decl) = TREE_PRIVATE (binfo);
- TREE_PROTECTED (decl) = TREE_PROTECTED (binfo);
if (is_empty_class (basetype))
/* CLASSTYPE_SIZE is one byte, but the field needs to have size zero. */
DECL_SIZE (decl) = DECL_SIZE_UNIT (decl) = size_zero_node;
SET_DECL_MODE (decl, TYPE_MODE (basetype));
DECL_FIELD_IS_BASE (decl) = 1;
+ if (access == access_private_node)
+ TREE_PRIVATE (decl) = true;
+ else if (access == access_protected_node)
+ TREE_PROTECTED (decl) = true;
+
/* Add the new FIELD_DECL to the list of fields for T. */
DECL_CHAIN (decl) = *next_field;
*next_field = decl;
Returns the location at which the next field should be inserted. */
static tree *
-build_base_field (record_layout_info rli, tree binfo,
+build_base_field (record_layout_info rli, tree binfo, tree access,
splay_tree offsets, tree *next_field)
{
tree t = rli->t;
CLASSTYPE_EMPTY_P (t) = 0;
/* Create the FIELD_DECL. */
- decl = build_base_field_1 (t, binfo, next_field);
+ decl = build_base_field_1 (t, binfo, access, next_field);
/* Try to place the field. It may take more than one try if we
have a hard time placing the field without putting two
aggregate bases. */
if (cxx_dialect >= cxx17 && !BINFO_VIRTUAL_P (binfo))
{
- tree decl = build_base_field_1 (t, binfo, next_field);
+ tree decl = build_base_field_1 (t, binfo, access, next_field);
DECL_FIELD_OFFSET (decl) = BINFO_OFFSET (binfo);
DECL_FIELD_BIT_OFFSET (decl) = bitsize_zero_node;
SET_DECL_OFFSET_ALIGN (decl, BITS_PER_UNIT);
/* Chain to hold all the new FIELD_DECLs which stand in for base class
subobjects. */
tree t = rli->t;
- int n_baseclasses = BINFO_N_BASE_BINFOS (TYPE_BINFO (t));
- int i;
+ tree binfo = TYPE_BINFO (t);
+ int n_baseclasses = BINFO_N_BASE_BINFOS (binfo);
/* The primary base class is always allocated first. */
- if (CLASSTYPE_HAS_PRIMARY_BASE_P (t))
- next_field = build_base_field (rli, CLASSTYPE_PRIMARY_BINFO (t),
- offsets, next_field);
+ const tree primary_binfo = CLASSTYPE_PRIMARY_BINFO (t);
+ if (primary_binfo)
+ {
+ /* We need to walk BINFO_BASE_BINFO to find the access of the primary
+ base, if it is direct. Indirect base fields are private. */
+ tree primary_access = access_private_node;
+ for (int i = 0; i < n_baseclasses; ++i)
+ {
+ tree base_binfo = BINFO_BASE_BINFO (binfo, i);
+ if (base_binfo == primary_binfo)
+ {
+ primary_access = BINFO_BASE_ACCESS (binfo, i);
+ break;
+ }
+ }
+ next_field = build_base_field (rli, primary_binfo,
+ primary_access,
+ offsets, next_field);
+ }
/* Now allocate the rest of the bases. */
- for (i = 0; i < n_baseclasses; ++i)
+ for (int i = 0; i < n_baseclasses; ++i)
{
- tree base_binfo;
-
- base_binfo = BINFO_BASE_BINFO (TYPE_BINFO (t), i);
+ tree base_binfo = BINFO_BASE_BINFO (binfo, i);
/* The primary base was already allocated above, so we don't
need to allocate it again here. */
- if (base_binfo == CLASSTYPE_PRIMARY_BINFO (t))
- continue;
+ if (base_binfo == primary_binfo)
+ continue;
/* Virtual bases are added at the end (a primary virtual base
will have already been added). */
continue;
next_field = build_base_field (rli, base_binfo,
+ BINFO_BASE_ACCESS (binfo, i),
offsets, next_field);
}
}
/* This virtual base is not a primary base of any class in the
hierarchy, so we have to add space for it. */
next_field = build_base_field (rli, vbase,
+ access_private_node,
offsets, next_field);
}
}