From patchwork Wed Jul 26 16:02:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 126480 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp501872vqo; Wed, 26 Jul 2023 09:04:49 -0700 (PDT) X-Google-Smtp-Source: APBJJlGEJOT0vwGACS9uHuIufgVuiQc3GEOqiJwNUFo4ys6JgmAAtv484KcHcZCpt5SgiZ8I3H0R X-Received: by 2002:a2e:9795:0:b0:2b4:7f2e:a433 with SMTP id y21-20020a2e9795000000b002b47f2ea433mr1791080lji.36.1690387489352; Wed, 26 Jul 2023 09:04:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690387489; cv=none; d=google.com; s=arc-20160816; b=cRj49+1UU8xEYicqCSe9oqaDNqKsFeC70dhJkYUKghCinC4VXIXU6LxLGbKFWEybUH EkDZta7quyiBZ+aswBuCkFOLfRkOgYrgdo53xDvMiABLjSoEAY/TUHyrO9jNMH3wmmsf taVQUwI2Yj+ktfq+oDtNOY3T+epWVCr5NzWUzIIjfuuPktBfXDXTnHzm2lxM07w7QSM2 R6loX4DhpeMi+saBpW6aEES6ke2Gur0ViW0QefcmEnJM7kdBDHPgTcB5OX71DmEBTSr0 tMMPP8vG0u4lHcBxE2ripW1WYFmb6FOwG2ebnVOsmpgiq82OIHk7gj/9VIL+kIp5vIhq +ipQ== 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=fHrSuNgkNHWyG3dacFD9t/ajvzTkOAJ1I+AMHp8QsQ8=; fh=sC8lnOfyH6gL5FYlMbZ1VDz6qVPMj/3ViLJWKNUCUgQ=; b=hZqBwScFLAEXPHtXQ4pzWrol1UwqE4HcLDtwn7PC4xrRhQFGFuk0+1aurS5UWi/JPS wWmcAeaVC1PEsrG+aTiaIGrR3D/iDTPYAC+XI59TBdX5ooD4pMbRNENvAk8uikGWrnCv 7hGn2nrwQjXWLW2fB+HstME0CoGvkl9m163kRMxTenx8AbqvjTTnEbON5XZTjyfQTebq iC4pJPdrOLVJ6m2D5S0rAWPbMXQDeegMhuI2uncLyNyp1kLjuIygoVBcejeL0dzP1pMB dSf2vQhyZkZonj3HRxlNnfgYDPNrI/QtQ8LfL4hpLfZY9yYOhnTVH7pQFL5dip1/6ADD 3ZJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=flTjenRl; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id jt6-20020a170906dfc600b00992fef5cff9si1230166ejc.497.2023.07.26.09.04.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 09:04:49 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=flTjenRl; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 A37643860757 for ; Wed, 26 Jul 2023 16:04:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A37643860757 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1690387452; bh=fHrSuNgkNHWyG3dacFD9t/ajvzTkOAJ1I+AMHp8QsQ8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=flTjenRlR5LfGVfAOCr9+GK4jtAY2qKcyy5iIRhrgUOVXj6OgKnJd40C7954ziYjb 078tZ4zdiI8OEbTpqqU/pSmjLAo30lIble4DQPixEqVeUXzAU+bEEm6F2e3LWj+jIu ovplju32yBISSSat7C4kKgAcyK1RLZUuJ+UAqXQg= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 08632385771D for ; Wed, 26 Jul 2023 16:03:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 08632385771D Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-461-_VhjsniQMnKIk3jylCYPcg-1; Wed, 26 Jul 2023 12:03:22 -0400 X-MC-Unique: _VhjsniQMnKIk3jylCYPcg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 995FA29ABA26; Wed, 26 Jul 2023 16:03:21 +0000 (UTC) Received: from localhost (unknown [10.42.28.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D3D3200B41D; Wed, 26 Jul 2023 16:03:21 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Add deprecated attribute to std::random_shuffle declarations Date: Wed, 26 Jul 2023 17:02:53 +0100 Message-ID: <20230726160320.220196-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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: INBOX X-GMAIL-THRID: 1772499751960963004 X-GMAIL-MSGID: 1772499751960963004 Tested x86_64-linux. Pushed to trunk. Probably worth backporting to 12 and 13. -- >8 -- We already have these attributes on the definitions in but they don't work due to PR c++/84542. Add the attributes to the declarations in as well, and add a test. libstdc++-v3/ChangeLog: * include/bits/algorithmfwd.h (random_shuffle): Add deprecated attribute. * include/bits/stl_algo.h (random_shuffle): Correct comments. * testsuite/25_algorithms/random_shuffle/1.cc: Disable deprecated warnings. * testsuite/25_algorithms/random_shuffle/59603.cc: Likewise. * testsuite/25_algorithms/random_shuffle/moveable.cc: Likewise. * testsuite/25_algorithms/random_shuffle/deprecated.cc: New test. --- libstdc++-v3/include/bits/algorithmfwd.h | 2 ++ libstdc++-v3/include/bits/stl_algo.h | 6 +++--- .../25_algorithms/random_shuffle/1.cc | 1 + .../25_algorithms/random_shuffle/59603.cc | 1 + .../random_shuffle/deprecated.cc | 19 +++++++++++++++++++ .../25_algorithms/random_shuffle/moveable.cc | 1 + 6 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 libstdc++-v3/testsuite/25_algorithms/random_shuffle/deprecated.cc diff --git a/libstdc++-v3/include/bits/algorithmfwd.h b/libstdc++-v3/include/bits/algorithmfwd.h index 0d623901cd2..130943d2340 100644 --- a/libstdc++-v3/include/bits/algorithmfwd.h +++ b/libstdc++-v3/include/bits/algorithmfwd.h @@ -832,10 +832,12 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO #if _GLIBCXX_HOSTED template + _GLIBCXX14_DEPRECATED_SUGGEST("std::shuffle") void random_shuffle(_RAIter, _RAIter); template + _GLIBCXX14_DEPRECATED_SUGGEST("std::shuffle") void random_shuffle(_RAIter, _RAIter, #if __cplusplus >= 201103L diff --git a/libstdc++-v3/include/bits/stl_algo.h b/libstdc++-v3/include/bits/stl_algo.h index 2c52ed51402..3abf0f69d46 100644 --- a/libstdc++-v3/include/bits/stl_algo.h +++ b/libstdc++-v3/include/bits/stl_algo.h @@ -4479,7 +4479,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * equally likely. * * @deprecated - * Since C++14 `std::random_shuffle` is not part of the C++ standard. + * Since C++17, `std::random_shuffle` is not part of the C++ standard. * Use `std::shuffle` instead, which was introduced in C++11. */ template @@ -4518,7 +4518,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * range `[0, N)`. * * @deprecated - * Since C++14 `std::random_shuffle` is not part of the C++ standard. + * Since C++17, `std::random_shuffle` is not part of the C++ standard. * Use `std::shuffle` instead, which was introduced in C++11. */ template @@ -4546,7 +4546,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO } } #endif // HOSTED -#endif // C++11 || USE_DEPRECATED +#endif // <= C++11 || USE_DEPRECATED /** * @brief Move elements for which a predicate is true to the beginning diff --git a/libstdc++-v3/testsuite/25_algorithms/random_shuffle/1.cc b/libstdc++-v3/testsuite/25_algorithms/random_shuffle/1.cc index 200c097f4a7..2a8c6323794 100644 --- a/libstdc++-v3/testsuite/25_algorithms/random_shuffle/1.cc +++ b/libstdc++-v3/testsuite/25_algorithms/random_shuffle/1.cc @@ -15,6 +15,7 @@ // with this library; see the file COPYING3. If not see // . +// { dg-options "-Wno-deprecated-declarations" } // { dg-add-options using-deprecated } // { dg-require-effective-target hosted } diff --git a/libstdc++-v3/testsuite/25_algorithms/random_shuffle/59603.cc b/libstdc++-v3/testsuite/25_algorithms/random_shuffle/59603.cc index c678eb333f2..a17429efba0 100644 --- a/libstdc++-v3/testsuite/25_algorithms/random_shuffle/59603.cc +++ b/libstdc++-v3/testsuite/25_algorithms/random_shuffle/59603.cc @@ -16,6 +16,7 @@ // . // { dg-do run { target c++11 } } +// { dg-options "-Wno-deprecated-declarations" } // { dg-add-options using-deprecated } // { dg-require-debug-mode "" } diff --git a/libstdc++-v3/testsuite/25_algorithms/random_shuffle/deprecated.cc b/libstdc++-v3/testsuite/25_algorithms/random_shuffle/deprecated.cc new file mode 100644 index 00000000000..4bc58a6447e --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/random_shuffle/deprecated.cc @@ -0,0 +1,19 @@ +// { dg-do compile } +// { dg-add-options using-deprecated } +// { dg-require-effective-target hosted } + +// std::random_shuffle was deprecated in C++17 and removed in C++17. + +#include + +std::ptrdiff_t rando(std::ptrdiff_t n); + +void +test_depr(int* first, int* last) +{ + std::random_shuffle(first, last); + // { dg-warning "deprecated" "" { target c++14 } 14 } + + std::random_shuffle(first, last, rando); + // { dg-warning "deprecated" "" { target c++14 } 17 } +} diff --git a/libstdc++-v3/testsuite/25_algorithms/random_shuffle/moveable.cc b/libstdc++-v3/testsuite/25_algorithms/random_shuffle/moveable.cc index 2e2cadaf862..e74e6f1c866 100644 --- a/libstdc++-v3/testsuite/25_algorithms/random_shuffle/moveable.cc +++ b/libstdc++-v3/testsuite/25_algorithms/random_shuffle/moveable.cc @@ -1,4 +1,5 @@ // { dg-do run { target c++11 } } +// { dg-options "-Wno-deprecated-declarations" } // { dg-add-options using-deprecated } // { dg-require-effective-target hosted }