From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 625FA3846426; Wed, 3 Apr 2024 10:46:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 625FA3846426 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1712141204; bh=I1e18s8qWK7AaqUREJnt0LuJtmS/Ym5uil2S+kLLahE=; h=From:To:Subject:Date:From; b=fiel6oZ6tFHH7kXszyFgNq2UM7pzcscCdIOQOLUR4FqbSRtUAuHoO79qaxPwjq4pC Fj8UGiCK4fbMBIiHoMmCLldeFX2yoCwcqjcPvDg21B5gB2rImo8dlo5JWu4xTYXJvV IdENFlkdAJR1UII/Eq5SKDxVc2KzUtA5V4oSIZms= 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 r13-8569] libstdc++: Constrain std::vector default constructor [PR113841] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-13 X-Git-Oldrev: d8d71b19f0b1e28fd6d413a6874ec55c568865b0 X-Git-Newrev: 87ec5b369eed205dfe6802afaaec3986b246ade9 Message-Id: <20240403104644.625FA3846426@sourceware.org> Date: Wed, 3 Apr 2024 10:46:44 +0000 (GMT) List-Id: https://gcc.gnu.org/g:87ec5b369eed205dfe6802afaaec3986b246ade9 commit r13-8569-g87ec5b369eed205dfe6802afaaec3986b246ade9 Author: Jonathan Wakely Date: Fri Feb 9 17:06:20 2024 +0000 libstdc++: Constrain std::vector default constructor [PR113841] This is needed to avoid errors outside the immediate context when evaluating is_default_constructible_v> when A is not default constructible. To avoid diagnostic regressions for 23_containers/vector/48101_neg.cc we need to make the std::allocator partial specializations default constructible, which they probably should have been anyway. libstdc++-v3/ChangeLog: PR libstdc++/113841 * include/bits/allocator.h (allocator): Add default constructor to partial specializations for cv-qualified types. * include/bits/stl_vector.h (_Vector_impl::_Vector_impl()): Constrain so that it's only present if the allocator is default constructible. * include/bits/stl_bvector.h (_Bvector_impl::_Bvector_impl()): Likewise. * testsuite/23_containers/vector/cons/113841.cc: New test. (cherry picked from commit 142cc4c223d695e515ed2504501b91d8a7ac6eb8) Diff: --- libstdc++-v3/include/bits/allocator.h | 3 ++ libstdc++-v3/include/bits/stl_bvector.h | 3 ++ libstdc++-v3/include/bits/stl_vector.h | 3 ++ .../testsuite/23_containers/vector/cons/113841.cc | 34 ++++++++++++++++++++++ 4 files changed, 43 insertions(+) diff --git a/libstdc++-v3/include/bits/allocator.h b/libstdc++-v3/include/bits/allocator.h index abbd753d33d..27e47521fe0 100644 --- a/libstdc++-v3/include/bits/allocator.h +++ b/libstdc++-v3/include/bits/allocator.h @@ -256,6 +256,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { public: typedef _Tp value_type; + allocator() { } template allocator(const allocator<_Up>&) { } }; @@ -264,6 +265,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { public: typedef _Tp value_type; + allocator() { } template allocator(const allocator<_Up>&) { } }; @@ -272,6 +274,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { public: typedef _Tp value_type; + allocator() { } template allocator(const allocator<_Up>&) { } }; /// @endcond diff --git a/libstdc++-v3/include/bits/stl_bvector.h b/libstdc++-v3/include/bits/stl_bvector.h index 8b54292e51b..e18de7c62aa 100644 --- a/libstdc++-v3/include/bits/stl_bvector.h +++ b/libstdc++-v3/include/bits/stl_bvector.h @@ -593,6 +593,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _GLIBCXX20_CONSTEXPR _Bvector_impl() _GLIBCXX_NOEXCEPT_IF( is_nothrow_default_constructible<_Bit_alloc_type>::value) +#if __cpp_concepts + requires is_default_constructible_v<_Bit_alloc_type> +#endif : _Bit_alloc_type() { } diff --git a/libstdc++-v3/include/bits/stl_vector.h b/libstdc++-v3/include/bits/stl_vector.h index acb29396d26..798e66d91ac 100644 --- a/libstdc++-v3/include/bits/stl_vector.h +++ b/libstdc++-v3/include/bits/stl_vector.h @@ -136,6 +136,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _GLIBCXX20_CONSTEXPR _Vector_impl() _GLIBCXX_NOEXCEPT_IF( is_nothrow_default_constructible<_Tp_alloc_type>::value) +#if __cpp_lib_concepts + requires is_default_constructible_v<_Tp_alloc_type> +#endif : _Tp_alloc_type() { } diff --git a/libstdc++-v3/testsuite/23_containers/vector/cons/113841.cc b/libstdc++-v3/testsuite/23_containers/vector/cons/113841.cc new file mode 100644 index 00000000000..a7721d27f79 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/cons/113841.cc @@ -0,0 +1,34 @@ +// { dg-do compile { target c++20 } } + +#include + +template +struct Alloc +{ + using value_type = T; + + Alloc(int) { } // not default constructible + + template Alloc(const Alloc&) { } + + T* allocate(std::size_t n) { return std::allocator().allocate(n); } + void deallocate(T* p, std::size_t n) { std::allocator().deallocate(p, n); } +}; + +template struct wrap { T t; }; + +template void do_adl(T&) { } + +void test_pr113841() +{ + using test_type = std::vector>; + std::pair>* h = nullptr; + do_adl(h); +} + +void test_pr113841_bool() +{ + using test_type = std::vector>; + std::pair>* h = nullptr; + do_adl(h); +}