From f82ece6b59622033b3dabf124d999d6f2fb1b6d7 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Wed, 21 Mar 2018 11:04:36 +0000 Subject: [PATCH] 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 --- gcc/ChangeLog | 5 ++ gcc/cp/ChangeLog | 5 ++ gcc/cp/class.c | 56 +++++++------------- gcc/cp/parser.c | 19 +++++-- gcc/doc/extend.texi | 26 ++++++--- gcc/testsuite/ChangeLog | 7 +++ gcc/testsuite/g++.dg/ext/anon-struct6.C | 2 +- gcc/testsuite/g++.dg/ext/deprecate-1.C | 22 ++++++++ gcc/testsuite/g++.dg/ext/deprecate-2.C | 4 ++ gcc/testsuite/g++.dg/lookup/pr84602.C | 6 +-- gcc/testsuite/g++.dg/lookup/pr84962.C | 2 +- gcc/testsuite/g++.old-deja/g++.other/anon4.C | 2 +- 12 files changed, 100 insertions(+), 56 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/deprecate-1.C create mode 100644 gcc/testsuite/g++.dg/ext/deprecate-2.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1f48794ee74..d886c45f10d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2018-03-21 Nathan Sidwell + + * doc/extend.texi (Deprecated Features): Update deprecared flags, + mention anon-struct/union members and trailing attributes. + 2018-03-21 Bin Cheng PR tree-optimization/84969 diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 5a37c8235bf..da19013d21c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,10 @@ 2018-03-21 Nathan Sidwell + * 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 8348552a05b..3edae0f5e61 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 c8a0e77aec6..4e3e1dccda0 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) diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index c0e779253cd..ce7862dbe6d 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -23824,23 +23824,25 @@ some cases that the feature will be dropped in the future. In other cases, the feature might be gone already. While the list below is not exhaustive, it documents some of the options -that are now deprecated: +that are now deprecated or have been removed: @table @code @item -fexternal-templates @itemx -falt-external-templates -These are two of the many ways for G++ to implement template -instantiation. @xref{Template Instantiation}. The C++ standard clearly -defines how template definitions have to be organized across -implementation units. G++ has an implicit instantiation mechanism that -should work just fine for standard-conforming code. +These are two options provided alternative methods of template +instantiation. @xref{Template Instantiation}. The options have been removed. @item -fstrict-prototype @itemx -fno-strict-prototype Previously it was possible to use an empty prototype parameter list to indicate an unspecified number of parameters (like C), rather than no -parameters, as C++ demands. This feature has been removed, except where -it is required for backwards compatibility. @xref{Backwards Compatibility}. +parameters, as C++ demands. This feature has been removed. + +@item -fno-for-scope +@item -ffriend-injection +These two options provide compatibility with pre-standard C++. +@xref{Backwards Compatibility}. + @end table G++ allows a virtual function returning @samp{void *} to be overridden @@ -23879,6 +23881,14 @@ initializers for static members of const integral types and const enumeration types so this extension has been deprecated and will be removed from a future version. +G++ allows attributes to follow a parenthesized direct initializer, +e.g.@: @samp{ int f (0) __attribute__ ((something)); } This extension +has been ignored since G++ 3.3 and is deprecated. + +G++ allows anonymous structs and unions to have members that are not +public non-static data members (i.e.@: fields). These extensions are +deprecated. + @node Backwards Compatibility @section Backwards Compatibility @cindex Backwards Compatibility diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ee0a40bab3d..a9deebe170c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,12 @@ 2018-03-21 Nathan Sidwell + * 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 + PR c++/84836 * g++.dg/lookup/pr84836.C: New. diff --git a/gcc/testsuite/g++.dg/ext/anon-struct6.C b/gcc/testsuite/g++.dg/ext/anon-struct6.C index 9b59085f670..360f25027a3 100644 --- a/gcc/testsuite/g++.dg/ext/anon-struct6.C +++ b/gcc/testsuite/g++.dg/ext/anon-struct6.C @@ -5,6 +5,6 @@ struct A struct { struct { static int i; }; // { dg-error "prohibits anonymous structs|non-static data members|unnamed class" } - void foo() { i; } // { dg-error "can only have non-static data" } + void foo() { i; } // { dg-error "public non-static data" } }; // { dg-error "prohibits anonymous structs" } }; diff --git a/gcc/testsuite/g++.dg/ext/deprecate-1.C b/gcc/testsuite/g++.dg/ext/deprecate-1.C new file mode 100644 index 00000000000..a23b71ba6ca --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/deprecate-1.C @@ -0,0 +1,22 @@ +// be pickier about anon-union and structs +// { dg-options "-fpermissive" } + +struct X +{ + struct + { + int f1 (); // { dg-warning "public non-static data" } + // { dg-message "will be removed" "" { target *-*-* } .-1 } + typedef int t1; // { dg-warning "public non-static data" } + private: + int m1; // { dg-warning "public non-static data" } + }; + + union + { + int f2 (); // { dg-warning "public non-static data" } + typedef int t2; // { dg-warning "public non-static data" } + protected: + int m2; // { dg-warning "public non-static data" } + }; +}; diff --git a/gcc/testsuite/g++.dg/ext/deprecate-2.C b/gcc/testsuite/g++.dg/ext/deprecate-2.C new file mode 100644 index 00000000000..5fcab2f6aac --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/deprecate-2.C @@ -0,0 +1,4 @@ +// Stop accepting attributes after a parenthesized initializer +// { dg-options "-fpermissive" } +int i (0) __attribute__ ((ignored)); // { dg-warning "attributes" } +// { dg-message "will be removed" "" { target *-*-* } .-1 } diff --git a/gcc/testsuite/g++.dg/lookup/pr84602.C b/gcc/testsuite/g++.dg/lookup/pr84602.C index d388ae00360..e1fc146a9ce 100644 --- a/gcc/testsuite/g++.dg/lookup/pr84602.C +++ b/gcc/testsuite/g++.dg/lookup/pr84602.C @@ -3,7 +3,7 @@ struct X { union { - class a; // { dg-warning "can only have" } + class a; // { dg-warning "public non-static data member" } }; a *b; }; @@ -11,7 +11,7 @@ X::a *a; struct Y { union { - class a; // { dg-warning "can only have" } + class a; // { dg-warning "public non-static data member" } int a; }; class a *b; @@ -23,7 +23,7 @@ struct Z { union { // Force MEMBER_VEC creation int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10; - class a; // { dg-warning "can only have" } + class a; // { dg-warning "public non-static data member" } int a; }; class a *b; diff --git a/gcc/testsuite/g++.dg/lookup/pr84962.C b/gcc/testsuite/g++.dg/lookup/pr84962.C index ee801c247bc..b9b7a313526 100644 --- a/gcc/testsuite/g++.dg/lookup/pr84962.C +++ b/gcc/testsuite/g++.dg/lookup/pr84962.C @@ -6,7 +6,7 @@ struct X { struct { template int a (); - // { dg-error "can only have" "" { target *-*-* } .-1 } + // { dg-error "public non-static data member" "" { target *-*-* } .-1 } }; int : a; // { dg-error "non-integral" } diff --git a/gcc/testsuite/g++.old-deja/g++.other/anon4.C b/gcc/testsuite/g++.old-deja/g++.other/anon4.C index b6cb3006d71..e6ed91b77ca 100644 --- a/gcc/testsuite/g++.old-deja/g++.other/anon4.C +++ b/gcc/testsuite/g++.old-deja/g++.other/anon4.C @@ -11,6 +11,6 @@ struct A { union { - void bad(); // { dg-error "can only have non-static data" } + void bad(); // { dg-error "public non-static data member" } }; }; -- 2.30.2