aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/class.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/cp/class.c')
-rw-r--r--gcc/cp/class.c56
1 files changed, 19 insertions, 37 deletions
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index 8348552..3edae0f 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -2869,9 +2869,7 @@ warn_hidden (tree t)
static void
finish_struct_anon_r (tree field, bool complain)
{
- bool is_union = TREE_CODE (TREE_TYPE (field)) == UNION_TYPE;
- tree elt = TYPE_FIELDS (TREE_TYPE (field));
- for (; elt; elt = DECL_CHAIN (elt))
+ for (tree elt = TYPE_FIELDS (TREE_TYPE (field)); elt; elt = DECL_CHAIN (elt))
{
/* We're generally only interested in entities the user
declared, but we also find nested classes by noticing
@@ -2885,50 +2883,34 @@ finish_struct_anon_r (tree field, bool complain)
|| TYPE_UNNAMED_P (TREE_TYPE (elt))))
continue;
- if (TREE_CODE (elt) != FIELD_DECL)
+ 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 (complain && !VAR_P (elt))
+ if (!VAR_P (elt)
+ && 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))
{
- if (is_union)
- permerror (DECL_SOURCE_LOCATION (elt),
- "%q#D invalid; an anonymous union can "
- "only have non-static data members", elt);
- else
- permerror (DECL_SOURCE_LOCATION (elt),
- "%q#D invalid; an anonymous struct can "
- "only have non-static data members", elt);
- }
- continue;
- }
-
- if (complain)
- {
- if (TREE_PRIVATE (elt))
- {
- if (is_union)
- permerror (DECL_SOURCE_LOCATION (elt),
- "private member %q#D in anonymous union", elt);
- else
- permerror (DECL_SOURCE_LOCATION (elt),
- "private member %q#D in anonymous struct", elt);
- }
- else if (TREE_PROTECTED (elt))
- {
- if (is_union)
- permerror (DECL_SOURCE_LOCATION (elt),
- "protected member %q#D in anonymous union", elt);
- else
- permerror (DECL_SOURCE_LOCATION (elt),
- "protected member %q#D in anonymous struct", 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);
- /* Recurse into the anonymous aggregates to handle correctly
+ /* Recurse into the anonymous aggregates to correctly handle
access control (c++/24926):
class A {