From patchwork Thu Jul 25 22:12:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1964926 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=BbXfQf+5; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WVQCD1CNcz20FJ for ; Fri, 26 Jul 2024 08:14:00 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 424C2385DDFB for ; Thu, 25 Jul 2024 22:13:58 +0000 (GMT) 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 ESMTP id DDF103858D20 for ; Thu, 25 Jul 2024 22:12:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DDF103858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DDF103858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721945579; cv=none; b=FquTeeqLbCCC0WymWwhMZcXDFGPQGYjet0vA2u0Ft9M4tclTwjY7hEGgdWF3wTrqg4u++OPjrrvQBP0XkI6HXsf10AvutTW0yuzMWYStkroU8btIM5UpFrCSKolQ+aajFNWjrsmXBIxi5YQFI/vPyQUkFFa8qCTFnu2N0KoAtTE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721945579; c=relaxed/simple; bh=Vl1alPflI2qNFAevIjJyecuszvMCfQ8+wS4jhwXUDvk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=JsfluNbtPv+w8CyB77LZnAevr3GUu7adEEABDz4fV59AEDBjcU0T3Zk/g8pFUa/3ooxK5GwC659hO5NuWgxyyJe6a3FPvIKQKKH1SaFCkFw0HkjS827an94BVXJ4HyFZh3NF47UZRdJFCh3ANSakjiOoIYqn+l0LQs/37BSTV+w= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721945576; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=3LrqpERaqJ90dU+bOa4oXNp/37qU/R6TkSEwr8ybjxs=; b=BbXfQf+5s0R5XkX7RbFniWsR9ITnyNr5iGpRuVz8+3Y1KB1z0f6Si9D7lscydPHZ10MHBF xDeBnOlPFwn1Amuk4OWYFf5/ZrRPlqAa3vxXnDkvXyR86irhFCVrOEHX7D6Kw42EDtsv8k 8DjPMIsbhfjRg/fWs7f4VdPZU+NOHLw= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-643-33_KkKvqPGS9wCRSjdspOA-1; Thu, 25 Jul 2024 18:12:53 -0400 X-MC-Unique: 33_KkKvqPGS9wCRSjdspOA-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 943451955D47; Thu, 25 Jul 2024 22:12:52 +0000 (UTC) Received: from localhost (unknown [10.42.28.14]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A9CD41955D42; Thu, 25 Jul 2024 22:12:51 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Implement P2968R2 "Making std::ignore a first-class object" Date: Thu, 25 Jul 2024 23:12:46 +0100 Message-ID: <20240725221250.151134-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=unavailable 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-linux. Pushed to trunk. -- >8 -- This was recently approved for C++26, but we can apply the changes for all modes back to C++11. There's no reason not to make the assignment usable in constant expressions for C++11 mode, and noexcept for all modes. Move the definitions to so they're available in as well as . libstdc++-v3/ChangeLog: * include/bits/utility.h (_Swallow_assign): Make assignment constexpr for C++11 as well, and add noexcept. * include/std/tuple (_Swallow_assign, ignore): Move to bits/utility.h. * testsuite/20_util/headers/utility/ignore.cc: New test. --- libstdc++-v3/include/bits/utility.h | 29 +++++++++++++++++ libstdc++-v3/include/std/tuple | 31 ------------------- .../20_util/headers/utility/ignore.cc | 29 +++++++++++++++++ 3 files changed, 58 insertions(+), 31 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/headers/utility/ignore.cc diff --git a/libstdc++-v3/include/bits/utility.h b/libstdc++-v3/include/bits/utility.h index 9f3b99231b3..44c74333e92 100644 --- a/libstdc++-v3/include/bits/utility.h +++ b/libstdc++-v3/include/bits/utility.h @@ -280,6 +280,35 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } // namespace __detail #endif + // A class (and instance) which can be used in 'tie' when an element + // of a tuple is not required. + struct _Swallow_assign + { + template + constexpr const _Swallow_assign& + operator=(const _Tp&) const noexcept + { return *this; } + }; + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 2773. Making std::ignore constexpr + /** Used with `std::tie` to ignore an element of a tuple + * + * When using `std::tie` to assign the elements of a tuple to variables, + * unwanted elements can be ignored by using `std::ignore`. For example: + * + * ``` + * int x, y; + * std::tie(x, std::ignore, y) = std::make_tuple(1, 2, 3); + * ``` + * + * This assignment will perform `x=1; std::ignore=2; y=3;` which results + * in the second element being ignored. + * + * @since C++11 + */ + _GLIBCXX17_INLINE constexpr _Swallow_assign ignore{}; + _GLIBCXX_END_NAMESPACE_VERSION } // namespace diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple index df3f6e38eeb..93b649e7d21 100644 --- a/libstdc++-v3/include/std/tuple +++ b/libstdc++-v3/include/std/tuple @@ -2845,37 +2845,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION swap(tuple<_Elements...>&, tuple<_Elements...>&) = delete; #endif - // A class (and instance) which can be used in 'tie' when an element - // of a tuple is not required. - // _GLIBCXX14_CONSTEXPR - // 2933. PR for LWG 2773 could be clearer - struct _Swallow_assign - { - template - _GLIBCXX14_CONSTEXPR const _Swallow_assign& - operator=(const _Tp&) const - { return *this; } - }; - - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // 2773. Making std::ignore constexpr - /** Used with `std::tie` to ignore an element of a tuple - * - * When using `std::tie` to assign the elements of a tuple to variables, - * unwanted elements can be ignored by using `std::ignore`. For example: - * - * ``` - * int x, y; - * std::tie(x, std::ignore, y) = std::make_tuple(1, 2, 3); - * ``` - * - * This assignment will perform `x=1; std::ignore=2; y=3;` which results - * in the second element being ignored. - * - * @since C++11 - */ - _GLIBCXX17_INLINE constexpr _Swallow_assign ignore{}; - /// Partial specialization for tuples template struct uses_allocator, _Alloc> : true_type { }; diff --git a/libstdc++-v3/testsuite/20_util/headers/utility/ignore.cc b/libstdc++-v3/testsuite/20_util/headers/utility/ignore.cc new file mode 100644 index 00000000000..fc7a45dc55b --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/headers/utility/ignore.cc @@ -0,0 +1,29 @@ +// { dg-do compile { target c++11 } } + +// P2968R2 Make std::ignore a first-class object. +// This is a C++26 change, but we treat it as a DR against C++11. + +// C++26 [tuple.general]: +// In addition to being available via inclusion of the header, +// ignore is available when is included. +#include + +using ignore_type = std::remove_const::type; + +#ifdef __cpp_lib_is_aggregate +static_assert( std::is_aggregate_v ); +#endif + +static_assert( std::is_nothrow_default_constructible::value, "" ); +static_assert( std::is_nothrow_copy_constructible::value, "" ); +static_assert( std::is_nothrow_copy_assignable::value, "" ); + +static_assert( std::is_nothrow_assignable::value, + "assignable from arbitrary types" ); +static_assert( std::is_nothrow_assignable::value, + "assignable from arbitrary types" ); + +constexpr ignore_type ignore; +constexpr ignore_type ignore_more(ignore); +constexpr ignore_type ignore_morer(ignore = ignore); +constexpr ignore_type ignore_morest(ignore = "");