aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/class.c
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2018-03-21 11:04:36 +0000
committerNathan Sidwell <nathan@gcc.gnu.org>2018-03-21 11:04:36 +0000
commitf82ece6b59622033b3dabf124d999d6f2fb1b6d7 (patch)
tree040f797e6109bd8be5c3cf2481cdbf62aced7f9b /gcc/cp/class.c
parent7cd9cf2f0bc24499c292896f951c2a34875637f0 (diff)
downloadgcc-f82ece6b59622033b3dabf124d999d6f2fb1b6d7.zip
gcc-f82ece6b59622033b3dabf124d999d6f2fb1b6d7.tar.gz
gcc-f82ece6b59622033b3dabf124d999d6f2fb1b6d7.tar.bz2
Deprecate some C++ extensions
https://gcc.gnu.org/ml/gcc-patches/2018-03/msg00995.html * doc/extend.texi (Deprecated Features): Update deprecared flags, mention anon-struct/union members and trailing attributes. cp/ * class.c (finish_struct_anon_r): Refactor, deprecate anything other than public non-static data members. * parser.c (cp_parser_init_declarator): Deprecate attributes after parenthesized initializer. testsuite/ * g++.dg/ext/anon-struct6.C: Adjust. * g++.dg/ext/deprecate-1.C: New. * g++.dg/ext/deprecate-2.C: New. * g++.dg/lookup/pr84602.C: Adjust. * g++.dg/lookup/pr84962.C: Adjust. * g++.old-deja/g++.other/anon4.C From-SVN: r258712
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 {