From patchwork Tue Jan 23 12:18:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 864753 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-471871-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="sKPcW7SV"; 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 3zQnQ70YzDz9t3w for ; Tue, 23 Jan 2018 23:18:20 +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=X6bir3b66aNj1JyN37YamOKBKn4q5Fu/tH9kerajGPEoamgLLr HjEvKa+HrQyVOqroxOXTz97XbB1SR3GXEQkz9vcCm1Dfgi9iy8Id346lobZdNIIB LMTRNEugbiexI7za7mfoJJBXMTA+xBiMpAnmX43wGA8uvCbc+oqEZqF8g= 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=LG3cAj5AM7mBfUvYo2EBRIbsbmo=; b=sKPcW7SVNASI1LbAhNgm Hh6AE2YEOt99UvcAhVq05mc9DZyD13L0qzLDAbYAfrM0YNheA042yplF0bihpEio K9Zqp1Mm8nwTGNDZlivMnPvnZ8GJdc6J7eayYHxC6SGEDovFn/Tc6N68vRKClrc1 KNziL3kD8CyL2cBfdXplKOI= Received: (qmail 125596 invoked by alias); 23 Jan 2018 12:18:13 -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 125201 invoked by uid 89); 23 Jan 2018 12:18:12 -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, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS, URIBL_RED autolearn=ham version=3.3.2 spammy=sk:nathan, signs, oldstyle, old-style X-HELO: mail-yw0-f171.google.com Received: from mail-yw0-f171.google.com (HELO mail-yw0-f171.google.com) (209.85.161.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 23 Jan 2018 12:18:10 +0000 Received: by mail-yw0-f171.google.com with SMTP id v139so93581ywg.4 for ; Tue, 23 Jan 2018 04:18:10 -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=Dym4fUepZ1UTVzwhIR2TZ3kZjY8tPlaqTVWmsiPSoWg=; b=SuR+fZpzOx3TUTyL4GIns/7yFfnYlFFHVdg6ZR5xKpdXriu7805+A74a2rulYzQ+Sh uzPgsonZhfhsL4IqwYFH8unjxr/ZSOevZmyF4kvJ6YN1nm3A/7StwXjI003M/cyMeGOa ZvdIiL9gtWWfPi2u3qYihkllPOh0jPH8EEV7g8jj/bGgEDKjKLV4tPkISY+gEgWdvGp+ Rr5h+whroioittLnElfEQgtzdVhAyZMvZxs1Jswcv0IIeRuOfyHvVvWl6VOXJa0int/S wWKzdlxGPruAFf2Bcv85i4f83Ui6IMnH+R5nYss0I9J/rYfiIw8CudYKR81EduOTK0tF 3w1Q== X-Gm-Message-State: AKwxytfI1EtBATSQtFuckFm6Laj7DXEwyW+xQJ9d+Ng+jcD1F/GnMu74 EJd+V+oUG4ubcuY0tcNqRTY= X-Google-Smtp-Source: AH8x224Ycy7AoKgdOvKvmvl/12TGJo79LvBv5oQuQrIqs07fZk5wlc2TN0IMURS94QvEmz7vKjR65Q== X-Received: by 10.13.224.65 with SMTP id j62mr2065284ywe.185.1516709888250; Tue, 23 Jan 2018 04:18:08 -0800 (PST) Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c091:200::2:280f]) by smtp.googlemail.com with ESMTPSA id g37sm7334049ywk.84.2018.01.23.04.18.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Jan 2018 04:18:07 -0800 (PST) To: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH] Deprecate ARM-era for scopes Message-ID: Date: Tue, 23 Jan 2018 07:18:06 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 As discussed (https://gcc.gnu.org/ml/gcc-patches/2018-01/msg01778.html) this patch deprecates the ARM-era for scope. a) in c++98 mode with -fpermissive, there's now a deprecation note when we fix up something like for (int i = ...) {} ... i ... // out of scope use of i b) -fno-for-scope gives a deprecated warning I noticed that the flag showed signs of being tri-valued at some point, but it is no longer (I suspect at some point we only attempted #a if neither sense of -ffor-scope was given). Cleaned that up. Applying to trunk. nathan 2018-01-23 Nathan Sidwell gcc/cp/ Deprecate ARM-era for scope handling * decl.c (poplevel): Flag_new_for_scope is a boolean-like. (cxx_init_decl_processing): Deprecate flag_new_for_scope being cleared. * name-lookup.c (check_for_out_of_scope_variable): Deprecate and cleanup handling. * semantics.c (begin_for_scope): Flag_new_for_scope is boolean-like. (finish_for_stmt, begin_range_for_stmt): Likewise. gcc/ * doc/invoke.texi (ffor-scope): Deprecate. gcc/cp/ * g++.dg/cpp0x/range-for10.C: Adjust. * g++.dg/ext/forscope1.C: Adjust. * g++.dg/ext/forscope2.C: Adjust. * g++.dg/template/for1.C: Adjust. Index: cp/decl.c =================================================================== --- cp/decl.c (revision 256951) +++ cp/decl.c (working copy) @@ -644,7 +644,7 @@ poplevel (int keep, int reverse, int fun in a init statement were in scope after the for-statement ended. We only use the new rules if flag_new_for_scope is nonzero. */ leaving_for_scope - = current_binding_level->kind == sk_for && flag_new_for_scope == 1; + = current_binding_level->kind == sk_for && flag_new_for_scope; /* Before we remove the declarations first check for unused variables. */ if ((warn_unused_variable || warn_unused_but_set_variable) @@ -4094,6 +4094,8 @@ cxx_init_decl_processing (void) pop_namespace (); flag_noexcept_type = (cxx_dialect >= cxx17); + if (!flag_new_for_scope) + warning (OPT_Wdeprecated, "%<-fno-for-scope%> is deprecated"); c_common_nodes_and_builtins (); Index: cp/name-lookup.c =================================================================== --- cp/name-lookup.c (revision 256951) +++ cp/name-lookup.c (working copy) @@ -3231,7 +3231,9 @@ push_local_binding (tree id, tree decl, standard. If so, issue an error message. If name lookup would work in both cases, but return a different result, this function returns the result of ANSI/ISO lookup. Otherwise, it returns - DECL. */ + DECL. + + FIXME: Scheduled for removal after GCC-8 is done. */ tree check_for_out_of_scope_variable (tree decl) @@ -3252,16 +3254,16 @@ check_for_out_of_scope_variable (tree de shadowed = find_namespace_value (current_namespace, DECL_NAME (decl)); if (shadowed) { - if (!DECL_ERROR_REPORTED (decl)) + if (!DECL_ERROR_REPORTED (decl) + && flag_permissive + && warning (0, "name lookup of %qD changed", DECL_NAME (decl))) { - warning (0, "name lookup of %qD changed", DECL_NAME (decl)); - warning_at (DECL_SOURCE_LOCATION (shadowed), 0, - " matches this %qD under ISO standard rules", - shadowed); - warning_at (DECL_SOURCE_LOCATION (decl), 0, - " matches this %qD under old rules", decl); - DECL_ERROR_REPORTED (decl) = 1; + inform (DECL_SOURCE_LOCATION (shadowed), + "matches this %qD under ISO standard rules", shadowed); + inform (DECL_SOURCE_LOCATION (decl), + " matches this %qD under old rules", decl); } + DECL_ERROR_REPORTED (decl) = 1; return shadowed; } @@ -3279,26 +3281,25 @@ check_for_out_of_scope_variable (tree de { error ("name lookup of %qD changed for ISO % scoping", DECL_NAME (decl)); - error (" cannot use obsolete binding at %q+D because " - "it has a destructor", decl); + inform (DECL_SOURCE_LOCATION (decl), + "cannot use obsolete binding %qD because it has a destructor", + decl); return error_mark_node; } else { - permerror (input_location, "name lookup of %qD changed for ISO % scoping", + permerror (input_location, + "name lookup of %qD changed for ISO % scoping", DECL_NAME (decl)); if (flag_permissive) - permerror (DECL_SOURCE_LOCATION (decl), - " using obsolete binding at %qD", decl); - else - { - static bool hint; - if (!hint) - { - inform (input_location, "(if you use %<-fpermissive%> G++ will accept your code)"); - hint = true; - } - } + inform (DECL_SOURCE_LOCATION (decl), + "using obsolete binding %qD", decl); + static bool hint; + if (!hint) + inform (input_location, flag_permissive + ? "this flexibility is deprecated and will be removed" + : "if you use %<-fpermissive%> G++ will accept your code"); + hint = true; } return decl; Index: cp/semantics.c =================================================================== --- cp/semantics.c (revision 256951) +++ cp/semantics.c (working copy) @@ -931,7 +931,7 @@ tree begin_for_scope (tree *init) { tree scope = NULL_TREE; - if (flag_new_for_scope > 0) + if (flag_new_for_scope) scope = do_pushlevel (sk_for); if (processing_template_decl) @@ -956,7 +956,7 @@ begin_for_stmt (tree scope, tree init) if (scope == NULL_TREE) { - gcc_assert (!init || !(flag_new_for_scope > 0)); + gcc_assert (!init || !flag_new_for_scope); if (!init) scope = begin_for_scope (&init); } @@ -1053,7 +1053,7 @@ finish_for_stmt (tree for_stmt) FOR_BODY (for_stmt) = do_poplevel (FOR_BODY (for_stmt)); /* Pop the scope for the body of the loop. */ - if (flag_new_for_scope > 0) + if (flag_new_for_scope) { tree scope; tree *scope_ptr = (TREE_CODE (for_stmt) == RANGE_FOR_STMT @@ -1082,7 +1082,7 @@ begin_range_for_stmt (tree scope, tree i if (scope == NULL_TREE) { - gcc_assert (!init || !(flag_new_for_scope > 0)); + gcc_assert (!init || !flag_new_for_scope); if (!init) scope = begin_for_scope (&init); } Index: doc/invoke.texi =================================================================== --- doc/invoke.texi (revision 256951) +++ doc/invoke.texi (working copy) @@ -2467,9 +2467,8 @@ a @i{for-init-statement} extends to the as was the case in old versions of G++, and other (traditional) implementations of C++. -If neither flag is given, the default is to follow the standard, -but to allow and give a warning for old-style code that would -otherwise be invalid, or have different behavior. +This option is deprecated and the associated non-standard +functionality will be removed. @item -fno-gnu-keywords @opindex fno-gnu-keywords Index: testsuite/g++.dg/cpp0x/range-for10.C =================================================================== --- testsuite/g++.dg/cpp0x/range-for10.C (revision 256951) +++ testsuite/g++.dg/cpp0x/range-for10.C (working copy) @@ -1,6 +1,6 @@ // PR c++/47388 // { dg-do compile { target c++11 } } -// { dg-options "-fno-for-scope" } +// { dg-options "-fno-for-scope -Wno-deprecated" } template void Index: testsuite/g++.dg/ext/forscope1.C =================================================================== --- testsuite/g++.dg/ext/forscope1.C (revision 256951) +++ testsuite/g++.dg/ext/forscope1.C (working copy) @@ -1,5 +1,5 @@ // { dg-do compile } -// { dg-options -fno-for-scope } +// { dg-options "-fno-for-scope -Wno-deprecated" } // Copyright (C) 2001 Free Software Foundation, Inc. // Contributed by Nathan Sidwell 4 Sept 2001 Index: testsuite/g++.dg/ext/forscope2.C =================================================================== --- testsuite/g++.dg/ext/forscope2.C (revision 256951) +++ testsuite/g++.dg/ext/forscope2.C (working copy) @@ -16,7 +16,7 @@ struct A void Go( ) { - for (int i = 1;;) // { dg-warning "using obsolete binding" } + for (int i = 1;;) // { dg-message "using obsolete binding" } { switch (1) { default: {} Index: testsuite/g++.dg/template/for1.C =================================================================== --- testsuite/g++.dg/template/for1.C (revision 256951) +++ testsuite/g++.dg/template/for1.C (working copy) @@ -1,6 +1,6 @@ // PR c++/47388 // { dg-do compile } -// { dg-options "-fno-for-scope" } +// { dg-options "-fno-for-scope -Wno-deprecated" } template void