aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/class.c
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2021-04-10 14:00:15 -0400
committerJason Merrill <jason@redhat.com>2021-04-29 14:34:05 -0400
commit58a92b789a77cdade1f41800efebf6e0686f9982 (patch)
tree480dac0f25d2e61c62b283b6090bb9c5ddf78588 /gcc/cp/class.c
parenta9fc64d8120937c5c37e1cacb2f55ae196e8897d (diff)
downloadgcc-58a92b789a77cdade1f41800efebf6e0686f9982.zip
gcc-58a92b789a77cdade1f41800efebf6e0686f9982.tar.gz
gcc-58a92b789a77cdade1f41800efebf6e0686f9982.tar.bz2
c++: ICE with anonymous union [PR97974]
While working on the GCC 11 patch, it occurred to me that we could move the errors about invalid members from finish_struct_anon_r to here, so we properly get a diagnostic in g++.law/union4.C. gcc/cp/ChangeLog: PR c++/97974 * class.c (finish_struct_anon_r): Drop complain parm. Remove non-field diagnostic. (finish_struct_anon): Adjust. * decl.c (fixup_anonymous_aggr): Move non-field diagnostic here. gcc/testsuite/ChangeLog: PR c++/97974 * g++.old-deja/g++.law/union4.C: Add expected diagnostic.
Diffstat (limited to 'gcc/cp/class.c')
-rw-r--r--gcc/cp/class.c34
1 files changed, 3 insertions, 31 deletions
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index 2cf527e..d693b43 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -3023,7 +3023,7 @@ warn_hidden (tree t)
/* Recursive helper for finish_struct_anon. */
static void
-finish_struct_anon_r (tree field, bool complain)
+finish_struct_anon_r (tree field)
{
for (tree elt = TYPE_FIELDS (TREE_TYPE (field)); elt; elt = DECL_CHAIN (elt))
{
@@ -3039,34 +3039,6 @@ finish_struct_anon_r (tree field, bool complain)
|| TYPE_UNNAMED_P (TREE_TYPE (elt))))
continue;
- if (complain
- && (TREE_CODE (elt) != FIELD_DECL
- || (TREE_PRIVATE (elt) || TREE_PROTECTED (elt))))
- {
- /* We already complained about static data members in
- finish_static_data_member_decl. */
- if (!VAR_P (elt))
- {
- auto_diagnostic_group d;
- if (permerror (DECL_SOURCE_LOCATION (elt),
- TREE_CODE (TREE_TYPE (field)) == UNION_TYPE
- ? "%q#D invalid; an anonymous union may "
- "only have public non-static data members"
- : "%q#D invalid; an anonymous struct may "
- "only have public non-static data members", elt))
- {
- static bool hint;
- if (flag_permissive && !hint)
- {
- hint = true;
- inform (DECL_SOURCE_LOCATION (elt),
- "this flexibility is deprecated and will be "
- "removed");
- }
- }
- }
- }
-
TREE_PRIVATE (elt) = TREE_PRIVATE (field);
TREE_PROTECTED (elt) = TREE_PROTECTED (field);
@@ -3084,7 +3056,7 @@ finish_struct_anon_r (tree field, bool complain)
int j=A().i; */
if (DECL_NAME (elt) == NULL_TREE
&& ANON_AGGR_TYPE_P (TREE_TYPE (elt)))
- finish_struct_anon_r (elt, /*complain=*/false);
+ finish_struct_anon_r (elt);
}
}
@@ -3103,7 +3075,7 @@ finish_struct_anon (tree t)
if (DECL_NAME (field) == NULL_TREE
&& ANON_AGGR_TYPE_P (TREE_TYPE (field)))
- finish_struct_anon_r (field, /*complain=*/true);
+ finish_struct_anon_r (field);
}
}