From patchwork Tue Mar 20 18:37:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 888392 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-475060-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Nw9KxbuV"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 405M9s4RwPz9s0n for ; Wed, 21 Mar 2018 05:37:36 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=Iv0DOSjSU1gzIkwojmfTwmh2AEo5Z8YUIWAAeB/IaQng70bIfn Q+20nj9ZtlDSS81GiL6/Qr0Db75HN/nagphEu6MqS6pr4wAdjOMANOtguyxiZcjN THQxrQ9993xVhldGva4Eglp5gGSgGQ1snhOg3zF1e/U1vijgjbuQAZqYw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=VoG03XahF/Ng4JKkOS6zFUIoVgc=; b=Nw9KxbuVqocmUcvOh4+D W0yrlXGTZUyQvS77rpB7jCHP3ZheAXIY7aT5JlDibxBT/Nsdy6wwIFg5oaMEW6fw N1zHGvm9XrjMpT/upOhVqJXZtDQdBfqeBBL14ZMBatnrSV1OY8Q+R8TUdO0tSGDA XNr1yy6BtwZFQBu6jTtwcZs= Received: (qmail 118725 invoked by alias); 20 Mar 2018 18:37:28 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 117603 invoked by uid 89); 20 Mar 2018 18:37:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-16.1 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=anon4c, anon4.C, Previously, demands X-HELO: mail-yw0-f179.google.com Received: from mail-yw0-f179.google.com (HELO mail-yw0-f179.google.com) (209.85.161.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 20 Mar 2018 18:37:25 +0000 Received: by mail-yw0-f179.google.com with SMTP id y203so864471ywg.5 for ; Tue, 20 Mar 2018 11:37:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:cc:from:subject:message-id:date :user-agent:mime-version:content-language; bh=PGzI+0uBxC3tjvVqefySBdVy/iL11K6jiI5t/ZoQ/z4=; b=YvVRijMACWaBHapCM78jnnHbPb3ZBZYP4vZ1Us0jv7cMlMbuTwmc7oJ9DYl+McW91P UZCsy7Q+bkDbzoWQBcohM8xgxjwW2xKC+ZtzVrA1Xe++vAG9aozuNCIcNKl1ONP3un1l U5gP5rJuA+1933BSVi5OuR5EngEVk/iqHztFek0+xnFQir1xo8M5hVIlCnnzYi6cslnD bPF/nQsRUwtGGRh4X4ra3CET282rp7WQ9y3izMAloLN7PSN9UKNFquA7kiNSvQ1+qRuZ 3b5Y30MHsJpCHfgFq2uMDmvJgq4gt4OU4E08+NJIjf0X7wucFFxMxV3bnOYQzKySCigC fz0Q== X-Gm-Message-State: AElRT7Gf9C+VT7HbESoh6xlaGipFiZT/f86oEonX0+MYlc0rBZMN2ASq Tdu4ZX5tXm1gYyMi7KpHGbQ= X-Google-Smtp-Source: AG47ELulCZeDXYLg0s21RNElPQytr37tVh57BLY+TGbE/X3Tm6Ug9xLtmSIH42e1JGVfONo6ZpQEKQ== X-Received: by 10.13.199.131 with SMTP id j125mr9839061ywd.185.1521571043886; Tue, 20 Mar 2018 11:37:23 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c091:200::2:ec9e]) by smtp.googlemail.com with ESMTPSA id v65sm871008ywb.33.2018.03.20.11.37.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Mar 2018 11:37:23 -0700 (PDT) To: Jason Merrill , Sandra Loosemore Cc: GCC Patches From: Nathan Sidwell Subject: Deprecate some C++ extensions Message-ID: Date: Tue, 20 Mar 2018 14:37:21 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 This patch deprecates 2 sets of extensions 1) 'T v (init) __attribute__ ((ignored))' That attribute placement has had no effect since the new parser (2002, I think gcc 3.3). Now we're more noisy about it. 2) anonymous struct or union members could be things other than public non-static data members. Now we're noisier about that too. I updated the 'Deprecated Features' piece of the documentation, it was mentioning some now-removed items as merely deprecated. It occurs to me we should probably just merge the 'Backwards Compatibility' section into 'Deprecated Features'. Perhaps add a 'Removed Features' section too? Sandra, WDYT? nathan 2018-03-20 Nathan Sidwell * 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 Index: cp/class.c =================================================================== --- cp/class.c (revision 258686) +++ cp/class.c (working copy) @@ -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 c || 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 { Index: cp/parser.c =================================================================== --- cp/parser.c (revision 258686) +++ cp/parser.c (working copy) @@ -19685,12 +19685,21 @@ cp_parser_init_declarator (cp_parser* pa /* 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) Index: doc/extend.texi =================================================================== --- doc/extend.texi (revision 258686) +++ doc/extend.texi (working copy) @@ -23824,23 +23824,25 @@ some cases that the feature will be drop 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 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 Index: testsuite/g++.dg/ext/anon-struct6.C =================================================================== --- testsuite/g++.dg/ext/anon-struct6.C (revision 258686) +++ testsuite/g++.dg/ext/anon-struct6.C (working copy) @@ -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" } }; Index: testsuite/g++.dg/ext/deprecate-1.C =================================================================== --- testsuite/g++.dg/ext/deprecate-1.C (revision 0) +++ testsuite/g++.dg/ext/deprecate-1.C (working copy) @@ -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" } + }; +}; Index: testsuite/g++.dg/ext/deprecate-2.C =================================================================== --- testsuite/g++.dg/ext/deprecate-2.C (revision 0) +++ testsuite/g++.dg/ext/deprecate-2.C (working copy) @@ -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 } Index: testsuite/g++.dg/lookup/pr84602.C =================================================================== --- testsuite/g++.dg/lookup/pr84602.C (revision 258686) +++ testsuite/g++.dg/lookup/pr84602.C (working copy) @@ -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; Index: testsuite/g++.dg/lookup/pr84962.C =================================================================== --- testsuite/g++.dg/lookup/pr84962.C (revision 258686) +++ testsuite/g++.dg/lookup/pr84962.C (working copy) @@ -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" } Index: testsuite/g++.old-deja/g++.other/anon4.C =================================================================== --- testsuite/g++.old-deja/g++.other/anon4.C (revision 258686) +++ testsuite/g++.old-deja/g++.other/anon4.C (working copy) @@ -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" } }; };