return atend;
}
+/* Build the FIELD_DECL for BASETYPE as a base of T, add it to the chain of
+ fields at NEXT_FIELD, and return it. */
+
+static tree
+build_base_field_1 (tree t, tree basetype, tree *&next_field)
+{
+ /* Create the FIELD_DECL. */
+ gcc_assert (CLASSTYPE_AS_BASE (basetype));
+ tree decl = build_decl (input_location,
+ FIELD_DECL, NULL_TREE, CLASSTYPE_AS_BASE (basetype));
+ DECL_ARTIFICIAL (decl) = 1;
+ DECL_IGNORED_P (decl) = 1;
+ DECL_FIELD_CONTEXT (decl) = t;
+ DECL_SIZE (decl) = CLASSTYPE_SIZE (basetype);
+ DECL_SIZE_UNIT (decl) = CLASSTYPE_SIZE_UNIT (basetype);
+ SET_DECL_ALIGN (decl, CLASSTYPE_ALIGN (basetype));
+ DECL_USER_ALIGN (decl) = CLASSTYPE_USER_ALIGN (basetype);
+ DECL_MODE (decl) = TYPE_MODE (basetype);
+ DECL_FIELD_IS_BASE (decl) = 1;
+
+ /* Add the new FIELD_DECL to the list of fields for T. */
+ DECL_CHAIN (decl) = *next_field;
+ *next_field = decl;
+ next_field = &DECL_CHAIN (decl);
+
+ return decl;
+}
+
/* Layout the base given by BINFO in the class indicated by RLI.
*BASE_ALIGN is a running maximum of the alignments of
any base class. OFFSETS gives the location of empty base
CLASSTYPE_EMPTY_P (t) = 0;
/* Create the FIELD_DECL. */
- decl = build_decl (input_location,
- FIELD_DECL, NULL_TREE, CLASSTYPE_AS_BASE (basetype));
- DECL_ARTIFICIAL (decl) = 1;
- DECL_IGNORED_P (decl) = 1;
- DECL_FIELD_CONTEXT (decl) = t;
- if (CLASSTYPE_AS_BASE (basetype))
- {
- DECL_SIZE (decl) = CLASSTYPE_SIZE (basetype);
- DECL_SIZE_UNIT (decl) = CLASSTYPE_SIZE_UNIT (basetype);
- SET_DECL_ALIGN (decl, CLASSTYPE_ALIGN (basetype));
- DECL_USER_ALIGN (decl) = CLASSTYPE_USER_ALIGN (basetype);
- DECL_MODE (decl) = TYPE_MODE (basetype);
- DECL_FIELD_IS_BASE (decl) = 1;
-
- /* Try to place the field. It may take more than one try if we
- have a hard time placing the field without putting two
- objects of the same type at the same address. */
- layout_nonempty_base_or_field (rli, decl, binfo, offsets);
- /* Add the new FIELD_DECL to the list of fields for T. */
- DECL_CHAIN (decl) = *next_field;
- *next_field = decl;
- next_field = &DECL_CHAIN (decl);
- }
+ decl = build_base_field_1 (t, basetype, 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
+ objects of the same type at the same address. */
+ layout_nonempty_base_or_field (rli, decl, binfo, offsets);
}
else
{
CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
}
- /* We do not create a FIELD_DECL for empty base classes because
- it might overlap some other field. We want to be able to
- create CONSTRUCTORs for the class by iterating over the
- FIELD_DECLs, and the back end does not handle overlapping
- FIELD_DECLs. */
+ /* We used to not create a FIELD_DECL for empty base classes because of
+ back end issues with overlapping FIELD_DECLs, but that doesn't seem to
+ be a problem anymore. We need them to handle initialization of C++17
+ aggregate bases. */
+ if (cxx_dialect >= cxx1z && !BINFO_VIRTUAL_P (binfo))
+ {
+ tree decl = build_base_field_1 (t, basetype, 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);
+ }
/* An empty virtual base causes a class to be non-empty
-- but in that case we do not need to clear CLASSTYPE_EMPTY_P
/* Make sure that empty classes are reflected in RLI at this
point. */
- include_empty_classes(rli);
+ include_empty_classes (rli);
/* Make sure not to create any structures with zero size. */
if (integer_zerop (rli_size_unit_so_far (rli)) && CLASSTYPE_EMPTY_P (t))
while (field
&& (TREE_CODE (field) != FIELD_DECL
|| (DECL_C_BIT_FIELD (field) && !DECL_NAME (field))
- || DECL_ARTIFICIAL (field)))
+ || (DECL_ARTIFICIAL (field)
+ && !(cxx_dialect >= cxx1z && DECL_FIELD_IS_BASE (field)))))
field = DECL_CHAIN (field);
return field;
if (max_bases)
{
vec_alloc (BINFO_BASE_ACCESSES (binfo), max_bases);
- /* An aggregate cannot have baseclasses. */
- CLASSTYPE_NON_AGGREGATE (ref) = 1;
+ /* A C++98 POD cannot have base classes. */
+ CLASSTYPE_NON_LAYOUT_POD_P (ref) = true;
if (TREE_CODE (ref) == UNION_TYPE)
error ("derived union %qT invalid", ref);
if (access == access_default_node)
access = default_access;
+ /* Before C++17, an aggregate cannot have base classes. In C++17, an
+ aggregate can't have virtual, private, or protected base classes. */
+ if (cxx_dialect < cxx1z
+ || access != access_public_node
+ || via_virtual)
+ CLASSTYPE_NON_AGGREGATE (ref) = true;
+
if (PACK_EXPANSION_P (basetype))
basetype = PACK_EXPANSION_PATTERN (basetype);
if (TREE_CODE (basetype) == TYPE_DECL)