From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id DC5D93857817; Fri, 26 Nov 2021 16:34:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DC5D93857817 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r10-10307] libstdc++: Add missing 'constexpr' to std::tuple [PR102270] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: 6a38ddc2e015ee178776f668337ed2a88d474f63 X-Git-Newrev: b3f135a50c3dd7fc04252e17d7fbb08ca95aa9a5 Message-Id: <20211126163455.DC5D93857817@sourceware.org> Date: Fri, 26 Nov 2021 16:34:55 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Nov 2021 16:34:56 -0000 https://gcc.gnu.org/g:b3f135a50c3dd7fc04252e17d7fbb08ca95aa9a5 commit r10-10307-gb3f135a50c3dd7fc04252e17d7fbb08ca95aa9a5 Author: Jonathan Wakely Date: Wed Sep 15 21:53:35 2021 +0100 libstdc++: Add missing 'constexpr' to std::tuple [PR102270] This backport to gcc-10 also includes r12-3637. 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.cc: New test. * testsuite/util/testsuite_allocator.h (SimpleAllocator): Add constexpr to constructor so it can be used for C++20 tests. Diff: --- libstdc++-v3/include/std/tuple | 13 +++++ .../testsuite/20_util/tuple/cons/102270.cc | 64 ++++++++++++++++++++++ libstdc++-v3/testsuite/util/testsuite_allocator.h | 2 +- 3 files changed, 78 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple index 99121532101..fac6d4d656b 100644 --- a/libstdc++-v3/include/std/tuple +++ b/libstdc++-v3/include/std/tuple @@ -90,26 +90,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) { } @@ -141,10 +147,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) { } @@ -154,11 +162,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) { } @@ -255,6 +265,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Base(__tag, __use_alloc<_Head>(__a)) { } template + _GLIBCXX20_CONSTEXPR _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a, const _Head& __head, const _Tail&... __tail) : _Inherited(__tag, __a, __tail...), @@ -389,6 +400,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : _Base(__tag, __use_alloc<_Head>(__a)) { } template + _GLIBCXX20_CONSTEXPR _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a, const _Head& __head) : _Base(__use_alloc<_Head, _Alloc, _Head>(__a), __head) { } @@ -872,6 +884,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.cc b/libstdc++-v3/testsuite/20_util/tuple/cons/102270.cc new file mode 100644 index 00000000000..5500cacab6d --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/cons/102270.cc @@ -0,0 +1,64 @@ +// { 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); + + const int c = 0; + std::tuple tii(std::allocator_arg, a, c, c); + + return true; +} +static_assert( construct_using_allocator() ); diff --git a/libstdc++-v3/testsuite/util/testsuite_allocator.h b/libstdc++-v3/testsuite/util/testsuite_allocator.h index e52ef788467..dacb4daf6b0 100644 --- a/libstdc++-v3/testsuite/util/testsuite_allocator.h +++ b/libstdc++-v3/testsuite/util/testsuite_allocator.h @@ -512,7 +512,7 @@ namespace __gnu_test { typedef Tp value_type; - SimpleAllocator() noexcept { } + constexpr SimpleAllocator() noexcept { } template SimpleAllocator(const SimpleAllocator&) { }