From patchwork Wed Sep 28 23:36:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1516 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f2ce:0:0:0:0:0 with SMTP id d14csp423319wrp; Wed, 28 Sep 2022 16:38:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5dbXm0yqB/HAK54GmwfqBTLo7JPGU7g1OxteOwHIpNL5NHZRAIpP44Ou4MCDqfQhB6LfxN X-Received: by 2002:a05:6402:4004:b0:457:e175:4db3 with SMTP id d4-20020a056402400400b00457e1754db3mr434602eda.407.1664408306502; Wed, 28 Sep 2022 16:38:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664408306; cv=none; d=google.com; s=arc-20160816; b=uE9RNNnZTSZon5LK9LHO3IPVNe/e7/z5b7g8FBDzEa2Aql5XBNY1xas3mcDgn5yAle 70Ef0kwzlIjDB3UfO55vPQc1WrcqgZoITLfC/iiWNwE1iAu+FXVBBRlcm2HwaESdNidz tNz+ClwYPQPch7+n/e29PLPXPbY60D+VZTZdk48NDRxiVytmLbbaYBDR9SaLmz1ck77L +7G2eXzYEwuZZDMM+cPRKzaAoOdDFdxUdric5RuCRqUP/VJK7nsp/2wzUWKKEak6O2ws yx3rLOpnImEEcA0H5iyiM9VzF8+5YbI0iEnMet2W+yx/o3GEyrdezD70bacpWSjqyCSg 3fXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=KAeEsT49CWVq1t/E5PVG0WcDlAAcrFCkklDnbtiwyZU=; b=wSBPGW1XvJgKWnqD/d7eRJB4NHEOIUt5uRWPy4qAcTmRy4COmfXndGUdS7oNUPkBn0 C+Pua7+JlaWTdLhGdHYUnM/RIL8Q2maZfgFYsj4nLIWVIQPlYrV1IM3mf9Ls8MjMO4iu OQepBKiEbikly98yhZWBVqQU6l5nppse2WH2zAma2AKkgjlezMlXNcaop7elO0wMj7HG J0kigyX6fvZD3bBAPMvgKJjygoID+OsDumVL6WCDhmIVZ5KNmvkOHWKcniBtahyNuHo9 b8TMyIrStjIFBDXauuCfipgM2ugBH0BwlLidxVFtXcIzey2S8sYDM20eJkCcFjSpFjiJ SbqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YUQp60Cx; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id t11-20020aa7d70b000000b004475c9ad046si5760042edq.620.2022.09.28.16.38.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Sep 2022 16:38:26 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YUQp60Cx; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 28B5F385AC3B for ; Wed, 28 Sep 2022 23:37:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 28B5F385AC3B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664408275; bh=KAeEsT49CWVq1t/E5PVG0WcDlAAcrFCkklDnbtiwyZU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=YUQp60CxhtwupxYO3pblmZ0lCr3u2hqz6Y27kleEEtLwprlJmZkgcbnYOZGGMyYgG vpe84qPOIDK+jf5CQmdqhtezKQXVg49r5ydNxqEyip1lofU4GRtmhF1bAAHv2eXqTg CycCxpyIPEpTJ4kN2yWhnjUC+dRMEqS2MKmKHZ3s= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id B5A99385781E for ; Wed, 28 Sep 2022 23:36:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B5A99385781E Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-114-ZnE_cRlnNOWhaUIZLPf9vg-1; Wed, 28 Sep 2022 19:36:35 -0400 X-MC-Unique: ZnE_cRlnNOWhaUIZLPf9vg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E7FD68027EA; Wed, 28 Sep 2022 23:36:34 +0000 (UTC) Received: from localhost (unknown [10.33.36.214]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9688F1121314; Wed, 28 Sep 2022 23:36:34 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Disable volatile-qualified std::bind for C++20 Date: Thu, 29 Sep 2022 00:36:34 +0100 Message-Id: <20220928233634.2670028-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1745258604493250330?= X-GMAIL-MSGID: =?utf-8?q?1745258604493250330?= Tested powerpc64le-linux. Pushed to trunk. -- >8 -- LWG 2487 added a precondition to std::bind for C++17, making volatile-qualified uses undefined. We still support it, but with a deprecated warning. P1065R2 made it explicitly ill-formed for C++20, so we should no longer accept it as deprecated. This implements that change. libstdc++-v3/ChangeLog: * doc/xml/manual/evolution.xml: Document std::bind API changes. * doc/xml/manual/intro.xml: Document LWG 2487 status. * doc/xml/manual/using.xml: Clarify default value of _GLIBCXX_USE_DEPRECATED. * doc/html/*: Regenerate. * include/std/functional (_Bind::operator()(Args&&...) volatile) (_Bind::operator()(Args&&...) const volatile) (_Bind_result::operator()(Args&&...) volatile) (_Bind_result::operator()(Args&&...) const volatile): Replace with deleted overload for C++20 and later. * testsuite/20_util/bind/cv_quals.cc: Check for deprecated warnings in C++17. * testsuite/20_util/bind/cv_quals_2.cc: Likewise, and check for ill-formed in C++20. --- libstdc++-v3/doc/html/index.html | 2 +- libstdc++-v3/doc/html/manual/api.html | 5 +++ libstdc++-v3/doc/html/manual/appendix.html | 2 +- .../doc/html/manual/appendix_porting.html | 2 +- libstdc++-v3/doc/html/manual/bugs.html | 6 ++++ libstdc++-v3/doc/html/manual/index.html | 2 +- .../doc/html/manual/using_macros.html | 5 +-- libstdc++-v3/doc/xml/manual/evolution.xml | 13 ++++++++ libstdc++-v3/doc/xml/manual/intro.xml | 9 ++++++ libstdc++-v3/doc/xml/manual/using.xml | 5 +-- libstdc++-v3/include/std/functional | 32 ++++++++++++++----- .../testsuite/20_util/bind/cv_quals.cc | 25 ++++++++------- .../testsuite/20_util/bind/cv_quals_2.cc | 12 ++++--- 13 files changed, 87 insertions(+), 33 deletions(-) diff --git a/libstdc++-v3/doc/xml/manual/evolution.xml b/libstdc++-v3/doc/xml/manual/evolution.xml index 4923e8c4783..82936189179 100644 --- a/libstdc++-v3/doc/xml/manual/evolution.xml +++ b/libstdc++-v3/doc/xml/manual/evolution.xml @@ -817,6 +817,10 @@ now defaults to zero. has_trivial_copy_assign removed. + +Calling a std::bind result as volatile was deprecated for C++17. + + Profile Mode was deprecated.
<constant>7.2</constant> @@ -1067,4 +1071,13 @@ the process.
+ +
<constant>12.3</constant> + +Calling a std::bind result as volatile is ill-formed for C++20 +and later. + + +
+ diff --git a/libstdc++-v3/doc/xml/manual/intro.xml b/libstdc++-v3/doc/xml/manual/intro.xml index d341c3efe6d..e3a03cf9d59 100644 --- a/libstdc++-v3/doc/xml/manual/intro.xml +++ b/libstdc++-v3/doc/xml/manual/intro.xml @@ -1163,6 +1163,15 @@ requirements of the license of GCC. ill-formed. + 2487: + bind() should be const-overloaded + not cv-overloaded + + + Deprecate volatile-qualified operator() + for C++17, make it ill-formed for C++20. + + 2499: operator>>(basic_istream&, CharT*) makes it hard to avoid buffer overflows diff --git a/libstdc++-v3/doc/xml/manual/using.xml b/libstdc++-v3/doc/xml/manual/using.xml index 0acdba6b3bd..9c444dd2997 100644 --- a/libstdc++-v3/doc/xml/manual/using.xml +++ b/libstdc++-v3/doc/xml/manual/using.xml @@ -1062,7 +1062,7 @@ g++ -Winvalid-pch -I. -include stdc++.h -H -g -O2 hello.cc -o test.exe #define/#undef). - ABI means that changing from the default value may + ABI-changing means that changing from the default value may mean changing the ABI of compiled code. In other words, these choices control code which has already been compiled (i.e., in a binary such as libstdc++.a/.so). If you explicitly #define or @@ -1077,7 +1077,8 @@ g++ -Winvalid-pch -I. -include stdc++.h -H -g -O2 hello.cc -o test.exe _GLIBCXX_USE_DEPRECATED - Defined by default. Not configurable. ABI-changing. Turning this off + Defined to the value 1 by default. + Not configurable. ABI-changing. Turning this off removes older ARM-style iostreams code, and other anachronisms from the API. This macro is dependent on the version of the standard being tracked, and as a result may give different results for diff --git a/libstdc++-v3/include/std/functional b/libstdc++-v3/include/std/functional index c4f75880fd8..5235ef20332 100644 --- a/libstdc++-v3/include/std/functional +++ b/libstdc++-v3/include/std/functional @@ -465,6 +465,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// @endcond +#if __cplusplus == 201703L && _GLIBCXX_USE_DEPRECATED +# define _GLIBCXX_VOLATILE_BIND +// _GLIBCXX_RESOLVE_LIB_DEFECTS +// 2487. bind() should be const-overloaded, not cv-overloaded +# define _GLIBCXX_DEPR_BIND \ + [[deprecated("std::bind does not support volatile in C++17")]] +#elif __cplusplus < 201703L +# define _GLIBCXX_VOLATILE_BIND +# define _GLIBCXX_DEPR_BIND +#endif + /// Type of the function object returned from bind(). template class _Bind; @@ -501,6 +512,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ); } +#ifdef _GLIBCXX_VOLATILE_BIND // Call as volatile template _Result @@ -522,6 +534,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Mu<_Bound_args>()(__volget<_Indexes>(_M_bound_args), __args)... ); } +#endif // volatile template using _Mu_type = decltype( @@ -585,12 +598,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Bound_indexes()); } -#if __cplusplus > 201402L -# define _GLIBCXX_DEPR_BIND \ - [[deprecated("std::bind does not support volatile in C++17")]] -#else -# define _GLIBCXX_DEPR_BIND -#endif +#ifdef _GLIBCXX_VOLATILE_BIND // Call as volatile template, add_volatile>> @@ -614,6 +622,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION std::forward_as_tuple(std::forward<_Args>(__args)...), _Bound_indexes()); } +#endif // volatile }; /// Type of the function object returned from bind(). @@ -649,9 +658,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION (std::get<_Indexes>(_M_bound_args), __args)...); } +#ifdef _GLIBCXX_VOLATILE_BIND // Call as volatile template - _GLIBCXX20_CONSTEXPR _Res __call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>) volatile { @@ -661,7 +670,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Call as const volatile template - _GLIBCXX20_CONSTEXPR _Res __call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>) const volatile @@ -669,6 +677,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return std::__invoke_r<_Res>(_M_f, _Mu<_Bound_args>() (__volget<_Indexes>(_M_bound_args), __args)...); } +#endif // volatile public: typedef _Result result_type; @@ -710,6 +719,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Bound_indexes()); } +#ifdef _GLIBCXX_VOLATILE_BIND // Call as volatile template _GLIBCXX_DEPR_BIND @@ -731,7 +741,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION std::forward_as_tuple(std::forward<_Args>(__args)...), _Bound_indexes()); } +#else + template + void operator()(_Args&&...) const volatile = delete; +#endif // volatile }; + +#undef _GLIBCXX_VOLATILE_BIND #undef _GLIBCXX_DEPR_BIND /** diff --git a/libstdc++-v3/testsuite/20_util/bind/cv_quals.cc b/libstdc++-v3/testsuite/20_util/bind/cv_quals.cc index 83312397a93..79e3e2fbdb4 100644 --- a/libstdc++-v3/testsuite/20_util/bind/cv_quals.cc +++ b/libstdc++-v3/testsuite/20_util/bind/cv_quals.cc @@ -17,6 +17,7 @@ // 20.7.11 Function template bind +// { dg-options "-Wdeprecated-declarations" } // { dg-do run { target c++11 } } #include @@ -48,12 +49,12 @@ void test01() const auto b1 = std::bind(X()); VERIFY( b1() == 1 ); -#if __cplusplus <= 201402L +#if __cplusplus <= 201703L volatile auto b2 = std::bind(X()); - VERIFY( b2() == 2 ); + VERIFY( b2() == 2 ); // { dg-warning "deprecated" "" { target c++17_only } } const volatile auto b3 = std::bind(X()); - VERIFY( b3() == 3 ); + VERIFY( b3() == 3 ); // { dg-warning "deprecated" "" { target c++17_only } } #endif } @@ -65,12 +66,12 @@ void test02() const auto b1 = std::bind(X()); VERIFY( b1() == 1 ); -#if __cplusplus <= 201402L +#if __cplusplus <= 201703L volatile auto b2 = std::bind(X()); - VERIFY( b2() == 2 ); + VERIFY( b2() == 2 ); // { dg-warning "deprecated" "" { target c++17_only } } const volatile auto b3 = std::bind(X()); - VERIFY( b3() == 3 ); + VERIFY( b3() == 3 ); // { dg-warning "deprecated" "" { target c++17_only } } #endif } @@ -82,12 +83,12 @@ void test03() const auto b1 = std::bind(X(), _1, 0, _2); VERIFY( b1(0, 0) == 1 ); -#if __cplusplus <= 201402L +#if __cplusplus <= 201703L volatile auto b2 = std::bind(X(), _1, _2, 0); - VERIFY( b2(0, 0) == 2 ); + VERIFY( b2(0, 0) == 2 ); // { dg-warning "deprecated" "" { target c++17_only } } const volatile auto b3 = std::bind(X(), _1, 0, _2); - VERIFY( b3(0, 0) == 3 ); + VERIFY( b3(0, 0) == 3 ); // { dg-warning "deprecated" "" { target c++17_only } } #endif } @@ -99,12 +100,12 @@ void test04() const auto b1 = std::bind(X(), _1, 0, _2); VERIFY( b1(0, 0) == 1 ); -#if __cplusplus <= 201402L +#if __cplusplus <= 201703L volatile auto b2 = std::bind(X(), _1, _2, 0); - VERIFY( b2(0, 0) == 2 ); + VERIFY( b2(0, 0) == 2 ); // { dg-warning "deprecated" "" { target c++17_only } } const volatile auto b3 = std::bind(X(), _1, 0, _2); - VERIFY( b3(0, 0) == 3 ); + VERIFY( b3(0, 0) == 3 ); // { dg-warning "deprecated" "" { target c++17_only } } #endif } diff --git a/libstdc++-v3/testsuite/20_util/bind/cv_quals_2.cc b/libstdc++-v3/testsuite/20_util/bind/cv_quals_2.cc index 7a85568c66a..d2ebad72fdf 100644 --- a/libstdc++-v3/testsuite/20_util/bind/cv_quals_2.cc +++ b/libstdc++-v3/testsuite/20_util/bind/cv_quals_2.cc @@ -15,7 +15,9 @@ // with this library; see the file COPYING3. If not see // . -// { dg-do run { target c++11 } } +// { dg-options "-Wdeprecated-declarations" } +// { dg-do run { target { c++11 && c++17_down } } } +// { dg-do compile { target c++20 } } #include #include @@ -33,13 +35,13 @@ void test01() const auto b0 = std::bind(X()); VERIFY( b0() == 0 ); -#if __cplusplus <= 201402L volatile auto b1 = std::bind(X()); - VERIFY( b1() == 1 ); + VERIFY( b1() == 1 ); // { dg-warning "deprecated" "" { target c++17_only } } + // { dg-error "no match" "" { target c++20 } 39 } const volatile auto b2 = std::bind(X()); - VERIFY( b2() == 2 ); -#endif + VERIFY( b2() == 2 ); // { dg-warning "deprecated" "" { target c++17_only } } + // { dg-error "no match" "" { target c++20 } 43 } } int main()