From patchwork Fri Feb 16 15:44:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 874480 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-473430-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="CRiEGvsP"; 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 3zjcrc3bqhz9t20 for ; Sat, 17 Feb 2018 02:44:15 +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 :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=ZTLVvPhrUvdfNH1jxVrA34KPz/ILTZPl0WvwQ3YXioO5HtP5Fv vYNHZDJiebvboXLOt7RKf7ShzNntIogk4b4t7RlA/DAf61nu7VZxUUTf4XFOsDri qHSNzhLpczzaOtAxZ6Vf7RflFsACji7XhG+bRVmTEbfmbupHyXuWGImjA= 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 :from:subject:message-id:date:mime-version:content-type; s= default; bh=oDqeWLKKMUUTawt8foYQ9im8kIQ=; b=CRiEGvsPsUzBe8x/DPxt RVa9EHj2zrqr6G3lnZwwH+XDPY3Q2ZLVtW25vwj7ZcufatSW925WB5aiXCO/IlHN d/LulfS+L7EEFBdadOIRNDdBekdSe8wv3cfLLpBGtaqOrG0rxi4opMMlDXC1INP2 LpMcKBfEijaIgneNtR4tJFo= Received: (qmail 27376 invoked by alias); 16 Feb 2018 15:44:07 -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 27351 invoked by uid 89); 16 Feb 2018 15:44:06 -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=imag, Friend X-HELO: mail-yb0-f179.google.com Received: from mail-yb0-f179.google.com (HELO mail-yb0-f179.google.com) (209.85.213.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 16 Feb 2018 15:44:04 +0000 Received: by mail-yb0-f179.google.com with SMTP id i15-v6so708879ybg.7 for ; Fri, 16 Feb 2018 07:44:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=NtimiZM72Mu9mRSqBPI7vdBbxZNzfkPPDbTO1WQve/s=; b=ngB7mVmAMwAS2T+QYGqHPSE6Qqyl50g0qokU3VFVHZ0OXC90OVIbSBZ1ITaoZIEGFs BCtx5YbafGTnErFCmDjVdpXmIj7dQuO9Wl1eglrG58Wj1Jcu8HERz3xCwcEOE2Ho8vS5 aPdDgL/o2ESg3Up2sL6DsZTMP5KBDJZpFO9ZiaepVS5j4eFAUqsg2kzZdMlMGBJntRgJ tLCM9ctAMOyTTF2xy2KaS8huXFUX78qLoT0spfKzkCZsLPCRIWSML/AposGiEY0TbVUH wcwg+3FARypXCVB0yr+pSK9hH/Z0Hd0K0sAd6kuhpAuee4OGyQUZqKX7EdNTRm9VTsf6 HAZA== X-Gm-Message-State: APf1xPDy9VPAbU1NvH1XZnPaNslo8LXYJ/ZZow/wfIz/otXDy9MP0umW VdgGfUf7yNipBrL8V8PUoJo= X-Google-Smtp-Source: AH8x225xIZ23CYQYNPje4r23y1+iq+E648mD/EkOJHvgbZurdw40Y3PK85Hc+IvVGlyayZa4J1ZWEA== X-Received: by 10.37.38.193 with SMTP id m184mr4863367ybm.74.1518795842313; Fri, 16 Feb 2018 07:44:02 -0800 (PST) Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c091:200::3:a8f3]) by smtp.googlemail.com with ESMTPSA id p204sm2537158ywe.15.2018.02.16.07.44.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Feb 2018 07:44:01 -0800 (PST) To: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH] Deprecate -ffriend-injection Message-ID: <34da4f83-10e6-7644-d8d8-be55abf1cb85@acm.org> Date: Fri, 16 Feb 2018 10:44:00 -0500 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 the -ffriend-injection option. 1) issue a deprecated warning, if the option is set. 2) if we do inject a visible friend, issue a warning. This warning is not inhibitable, like the for-scope behaviour. (Notice we never injected visible friend classes, only functions). 3) Update the 'backwards compatibility' section to mention this. I noticed that at the point we warn about the flag, input_location is BUILTINS_LOCATION. There isn't a known fixed location for or . I think using UNKNOWN_LOCATION, which generates 'cc1plus: diag...', is less confusing than ': diag...'. 'Now that there is a definitive ISO standard C++, G++ has a specification to adhere to.' We now have several :) nathan 2018-02-16 Nathan Sidwell Deprecate -ffriend-injection. * decl.c (cxx_init_decl_processing): Emit warning on option. * name-lookup.c (do_pushdecl): Emit warning if we push a visible friend. * doc/extend.texi (Backwards Compatibility): Mention friend injection. Note for-scope is deprecated. * doc/invoke.texi (-ffriend-injection): Deprecate. * g++.old-deja/g++.jason/scoping15.C: Expect warnings. * g++.old-deja/g++.mike/net43.C: Likewise. Index: cp/decl.c =================================================================== --- cp/decl.c (revision 257739) +++ cp/decl.c (working copy) @@ -4091,8 +4091,14 @@ cxx_init_decl_processing (void) pop_namespace (); flag_noexcept_type = (cxx_dialect >= cxx17); + /* There's no fixed location for , the current + location is , which is somewhat confusing. */ if (!flag_new_for_scope) - warning (OPT_Wdeprecated, "%<-fno-for-scope%> is deprecated"); + warning_at (UNKNOWN_LOCATION, OPT_Wdeprecated, + "%<-fno-for-scope%> is deprecated"); + if (flag_friend_injection) + warning_at (UNKNOWN_LOCATION, OPT_Wdeprecated, + "%<-ffriend-injection%> is deprecated"); c_common_nodes_and_builtins (); Index: cp/name-lookup.c =================================================================== --- cp/name-lookup.c (revision 257739) +++ cp/name-lookup.c (working copy) @@ -3071,6 +3071,7 @@ do_pushdecl (tree decl, bool is_friend) old = OVL_CHAIN (old); check_template_shadow (decl); + bool visible_injection = false; if (DECL_DECLARES_FUNCTION_P (decl)) { @@ -3091,6 +3092,8 @@ do_pushdecl (tree decl, bool is_friend) if (!flag_friend_injection) /* Hide it from ordinary lookup. */ DECL_ANTICIPATED (decl) = DECL_HIDDEN_FRIEND_P (decl) = true; + else + visible_injection = true; } } @@ -3142,6 +3145,9 @@ do_pushdecl (tree decl, bool is_friend) } else if (VAR_P (decl)) maybe_register_incomplete_var (decl); + else if (visible_injection) + warning (0, "injected friend %qD is visible" + " due to %<-ffriend-injection%>", decl); if ((VAR_P (decl) || TREE_CODE (decl) == FUNCTION_DECL) && DECL_EXTERN_C_P (decl)) Index: doc/extend.texi =================================================================== --- doc/extend.texi (revision 257739) +++ doc/extend.texi (working copy) @@ -23881,11 +23881,23 @@ deprecated. @xref{Deprecated Features} @table @code @item For scope -If a variable is declared at for scope, it used to remain in scope until -the end of the scope that contained the for statement (rather than just -within the for scope). G++ retains this, but issues a warning, if such a +If a variable is declared at for scope, it used to remain in scope +until the end of the scope that contained the for statement (rather +than just within the for scope). The deprecated +@option{-fno-for-scope} option enables this non-standard behaviour. +Without the option, G++ retains this, but issues a warning, if such a variable is accessed outside the for scope. +The behaviour is deprecated, only available with @option{-std=c++98} +@option{-std=gnu++98} languages and you must use the +@option{-fpermissive} option to enable it. The behaviour will be +removed. + +@item Friend Injection +The @option{-ffriend-injection} option makes injected friends visible +to regular name lookup, unlike standard C++. This option is +deprecated and will be removed. + @item Implicit C language Old C system header files did not contain an @code{extern "C" @{@dots{}@}} scope to set the language. On such systems, all header files are Index: doc/invoke.texi =================================================================== --- doc/invoke.texi (revision 257739) +++ doc/invoke.texi (working copy) @@ -2451,8 +2451,7 @@ However, in ISO C++ a friend function th in an enclosing scope can only be found using argument dependent lookup. GCC defaults to the standard behavior. -This option is for compatibility, and may be removed in a future -release of G++. +This option is deprecated and will be removed. @item -fno-elide-constructors @opindex fno-elide-constructors Index: testsuite/g++.old-deja/g++.jason/scoping15.C =================================================================== --- testsuite/g++.old-deja/g++.jason/scoping15.C (revision 257739) +++ testsuite/g++.old-deja/g++.jason/scoping15.C (working copy) @@ -3,14 +3,17 @@ // Bug: g++ ignores the :: qualification and dies trying to treat an integer // variable as a list of functions. +class DComplex; +double imag (const DComplex&); + class DComplex { public: - friend double imag(const DComplex& a); + friend double imag(const DComplex& a); // Not injected, no warning }; class FComplex { public: - friend float imag(const FComplex& a); + friend float imag(const FComplex& a); // { dg-warning "is visible" }; void @@ -19,3 +22,4 @@ scnrm2(FComplex cx[]) int imag; ::imag( cx[0] ); } +// { dg-warning "ffriend-injection.* is deprecated" "" { target *-*-* } cc1plus: } Index: testsuite/g++.old-deja/g++.mike/net43.C =================================================================== --- testsuite/g++.old-deja/g++.mike/net43.C (revision 257739) +++ testsuite/g++.old-deja/g++.mike/net43.C (working copy) @@ -1,9 +1,9 @@ // { dg-do assemble } -// { dg-options "-ffriend-injection" } +// { dg-options "-ffriend-injection -Wno-deprecated" } class foo { public: - friend int operator ^(const foo&, const foo&); + friend int operator ^(const foo&, const foo&); // { dg-message "is visible" } }; int main ()