From patchwork Thu Sep 16 22:07:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 45099 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2752A385AC1D for ; Thu, 16 Sep 2021 22:14:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2752A385AC1D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1631830442; bh=mrXfTUl10frYwxLYrvd5hL151ttEDuqFmz85VsjvIt4=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=hxXssJYEljCUURitKe6Yx30/Ej/XA/Lqyvb3NDUf7kBBe4OQwdzWU7bQOWhDBfY14 NR9G2b/2UQP4MyuazVauUYbNQnK3CZJdeDeCc108bWOyS8f/w1sZ1TfD+v/giCKvdc 9oYqPXvLhyjZJg4bWKWzGL43B9XmLgwyvYZqRQR8= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id C12243857418 for ; Thu, 16 Sep 2021 22:07:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C12243857418 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-223-ZVkm_e6ZOWyseHf-eDPpXw-1; Thu, 16 Sep 2021 18:07:53 -0400 X-MC-Unique: ZVkm_e6ZOWyseHf-eDPpXw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F31421006AA6; Thu, 16 Sep 2021 22:07:52 +0000 (UTC) Received: from localhost (unknown [10.33.36.240]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9FF051B4B8; Thu, 16 Sep 2021 22:07:52 +0000 (UTC) Date: Thu, 16 Sep 2021 23:07:51 +0100 To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Add missing 'constexpr' to std::tuple [PR102270] Message-ID: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-14.0 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_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=unavailable autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Signed-off-by: Jonathan Wakely libstdc++-v3/ChangeLog: PR libstdc++/102270 * include/std/tuple (_Head_base, _Tuple_impl): Add _GLIBCXX20_CONSTEXPR to allocator-extended constructors. (tuple<>::swap(tuple&)): Add _GLIBCXX20_CONSTEXPR. * testsuite/20_util/tuple/cons/102270.C: New test. Tested x86_64-linux. Committed to trunk. commit 734b2c2eedca50d966e22540fc136158c3633393 Author: Jonathan Wakely Date: Wed Sep 15 21:53:35 2021 libstdc++: Add missing 'constexpr' to std::tuple [PR102270] Signed-off-by: Jonathan Wakely libstdc++-v3/ChangeLog: PR libstdc++/102270 * include/std/tuple (_Head_base, _Tuple_impl): Add _GLIBCXX20_CONSTEXPR to allocator-extended constructors. (tuple<>::swap(tuple&)): Add _GLIBCXX20_CONSTEXPR. * testsuite/20_util/tuple/cons/102270.C: New test. diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple index f082ccb8a3b..6f0dc6346e1 100644 --- a/libstdc++-v3/include/std/tuple +++ b/libstdc++-v3/include/std/tuple @@ -95,10 +95,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : _M_head_impl() { } template + _GLIBCXX20_CONSTEXPR _Head_base(allocator_arg_t, __uses_alloc1<_Alloc> __a) : _M_head_impl(allocator_arg, *__a._M_a) { } template + _GLIBCXX20_CONSTEXPR _Head_base(allocator_arg_t, __uses_alloc2<_Alloc> __a) : _M_head_impl(*__a._M_a) { } @@ -108,11 +110,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : _M_head_impl(std::forward<_UHead>(__uhead)) { } template + _GLIBCXX20_CONSTEXPR _Head_base(__uses_alloc1<_Alloc> __a, _UHead&& __uhead) : _M_head_impl(allocator_arg, *__a._M_a, std::forward<_UHead>(__uhead)) { } template + _GLIBCXX20_CONSTEXPR _Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead) : _M_head_impl(std::forward<_UHead>(__uhead), *__a._M_a) { } @@ -142,26 +146,32 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION constexpr _Head_base(_UHead&& __h) : _Head(std::forward<_UHead>(__h)) { } + _GLIBCXX20_CONSTEXPR _Head_base(allocator_arg_t, __uses_alloc0) : _Head() { } template + _GLIBCXX20_CONSTEXPR _Head_base(allocator_arg_t, __uses_alloc1<_Alloc> __a) : _Head(allocator_arg, *__a._M_a) { } template + _GLIBCXX20_CONSTEXPR _Head_base(allocator_arg_t, __uses_alloc2<_Alloc> __a) : _Head(*__a._M_a) { } template + _GLIBCXX20_CONSTEXPR _Head_base(__uses_alloc0, _UHead&& __uhead) : _Head(std::forward<_UHead>(__uhead)) { } template + _GLIBCXX20_CONSTEXPR _Head_base(__uses_alloc1<_Alloc> __a, _UHead&& __uhead) : _Head(allocator_arg, *__a._M_a, std::forward<_UHead>(__uhead)) { } template + _GLIBCXX20_CONSTEXPR _Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead) : _Head(std::forward<_UHead>(__uhead), *__a._M_a) { } @@ -194,10 +204,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : _M_head_impl() { } template + _GLIBCXX20_CONSTEXPR _Head_base(allocator_arg_t, __uses_alloc1<_Alloc> __a) : _M_head_impl(allocator_arg, *__a._M_a) { } template + _GLIBCXX20_CONSTEXPR _Head_base(allocator_arg_t, __uses_alloc2<_Alloc> __a) : _M_head_impl(*__a._M_a) { } @@ -207,11 +219,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : _M_head_impl(std::forward<_UHead>(__uhead)) { } template + _GLIBCXX20_CONSTEXPR _Head_base(__uses_alloc1<_Alloc> __a, _UHead&& __uhead) : _M_head_impl(allocator_arg, *__a._M_a, std::forward<_UHead>(__uhead)) { } template + _GLIBCXX20_CONSTEXPR _Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead) : _M_head_impl(std::forward<_UHead>(__uhead), *__a._M_a) { } @@ -467,6 +481,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { } template + _GLIBCXX20_CONSTEXPR _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a, const _Head& __head) : _Base(__use_alloc<_Head, _Alloc, const _Head&>(__a), __head) @@ -955,6 +970,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION class tuple<> { public: + _GLIBCXX20_CONSTEXPR void swap(tuple&) noexcept { /* no-op */ } // We need the default since we're going to define no-op // allocator constructors. diff --git a/libstdc++-v3/testsuite/20_util/tuple/cons/102270.C b/libstdc++-v3/testsuite/20_util/tuple/cons/102270.C new file mode 100644 index 00000000000..998329817c7 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/cons/102270.C @@ -0,0 +1,61 @@ +// { dg-options "-std=gnu++20" } +// { dg-do compile { target c++20 } } + +#include + +// PR libstdc++/102270 - std::tuple<>::swap missing constexpr specifier + +constexpr bool swap_empty_tuple() +{ + std::tuple<> t, u; + t.swap(u); + return true; +} +static_assert( swap_empty_tuple() ); + +#include + +constexpr bool construct_using_allocator() +{ + using Alloc = __gnu_test::SimpleAllocator; + + Alloc a; + const int i = 0; + + struct X0a { + using allocator_type = Alloc; + /* not constexpr */ X0a() { } + constexpr X0a(allocator_type) { } + }; + std::tuple t0a(std::allocator_arg, a); + std::tuple t00a(std::allocator_arg, a); + + struct X0b { + using allocator_type = Alloc; + /* not constexpr */ X0b() { } + constexpr X0b(std::allocator_arg_t, allocator_type) { } + }; + std::tuple t0b(std::allocator_arg, a); + std::tuple t00b(std::allocator_arg, a); + + struct X1a { + using allocator_type = Alloc; + /* not constexpr */ X1a(int) { } + constexpr X1a(int, allocator_type) { } + }; + std::tuple t1a(std::allocator_arg, a, 1); + std::tuple t11a(std::allocator_arg, a, 1, i); + + struct X1b { + using allocator_type = Alloc; + /* not constexpr */ X1b(int) { } + constexpr X1b(std::allocator_arg_t, allocator_type, int) { } + }; + std::tuple t1b(std::allocator_arg, a, 1); + std::tuple t11b(std::allocator_arg, a, 1, i); + + std::tuple t1a1b(std::allocator_arg, a, 1, i, 1, i); + + return true; +} +static_assert( construct_using_allocator() );