In discussion of jakub's patch for C++20 pointer-interconvertibility, it
came up that we allow anonymous structs to have bases, but don't do anything
usable with them. Let's reject it.
The comment change is something I noticed while looking for the right place
to diagnose this: finish_struct_anon does not actually check for anything
invalid, so it shouldn't claim to.
gcc/cp/ChangeLog:
* class.c (finish_struct_anon): Improve comment.
* decl.c (fixup_anonymous_aggr): Reject anonymous struct
with bases.
gcc/testsuite/ChangeLog:
* g++.dg/ext/anon-struct8.C: New test.
}
}
-/* Check for things that are invalid. There are probably plenty of other
- things we should check for also. */
+/* Fix up any anonymous union/struct members of T. */
static void
finish_struct_anon (tree t)
{
tree field, type;
+ if (BINFO_N_BASE_BINFOS (TYPE_BINFO (t)))
+ error_at (location_of (t), "anonymous struct with base classes");
+
for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
if (TREE_CODE (field) == FIELD_DECL)
{
--- /dev/null
+// { dg-options "" }
+
+struct A { };
+struct B {
+ struct: A { int i; }; // { dg-error "anonymous struct with base" }
+};
+union U {
+ struct: A { int i; }; // { dg-error "anonymous struct with base" }
+};