aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/class.c56
-rw-r--r--gcc/cp/parser.c19
3 files changed, 38 insertions, 42 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 5a37c82..da19013 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,10 @@
2018-03-21 Nathan Sidwell <nathan@acm.org>
+ * 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.
+
PR c++/84836
* name-lookup.c (update_binding): Correct logic for local binding
update.
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 {
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index c8a0e77..4e3e1dc 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -19685,12 +19685,21 @@ cp_parser_init_declarator (cp_parser* parser,
/* The old parser allows attributes to appear after a parenthesized
initializer. Mark Mitchell proposed removing this functionality
on the GCC mailing lists on 2002-08-13. This parser accepts the
- attributes -- but ignores them. */
+ attributes -- but ignores them. Made a permerror in GCC 8. */
if (cp_parser_allow_gnu_extensions_p (parser)
- && initialization_kind == CPP_OPEN_PAREN)
- if (cp_parser_attributes_opt (parser))
- warning (OPT_Wattributes,
- "attributes after parenthesized initializer ignored");
+ && initialization_kind == CPP_OPEN_PAREN
+ && cp_parser_attributes_opt (parser)
+ && permerror (input_location,
+ "attributes after parenthesized initializer ignored"))
+ {
+ static bool hint;
+ if (flag_permissive && !hint)
+ {
+ hint = true;
+ inform (input_location,
+ "this flexibility is deprecated and will be removed");
+ }
+ }
/* And now complain about a non-function implicit template. */
if (bogus_implicit_tmpl && decl != error_mark_node)