From patchwork Tue Mar 19 15:57:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1913698 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=H3lZgdwX; 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 4Tzbyk36h6z1yX9 for ; Wed, 20 Mar 2024 02:59:58 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6F20F385842B for ; Tue, 19 Mar 2024 15:59:56 +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.133.124]) by sourceware.org (Postfix) with ESMTPS id 950D73858CD1 for ; Tue, 19 Mar 2024 15:59:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 950D73858CD1 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 950D73858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710863947; cv=none; b=k9MBcXMkdKuUEuZ5NIyEmY/rmcmOwdOqX9DWhfD47SJpC62b8lIK4SlwyvIBTtOjNLPogTGX6lSl8NJF5WL1BQnX8fvgH9mjq1iSk2V3j19L92U6uAhs3iNWg8YzSimKPvM/spVZYwq9/rpgkEIJRTGPftsjpPPkDaSwgvVDV5o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710863947; c=relaxed/simple; bh=mVlVPFWvIbq6T3IftiRM3OxBdMDMjUqolhfXGPyfudI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ILUmNVxRT5+ETIF9W3/iPcjz/4Hxmd8ITFMIHveJUo69516mY786q3Hd3uJp7VZru8ZjCvTtwmi8kbS6gc94wb1G7j0+AxC2j1hYLuOcsXlOyB8xoASelPX8hPp23tY0SiEbU3LDy26L3mOTIUUtvBohIsAmoLCcQursM90AYHA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710863945; 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=EvgEESmVK3GXmVdq6t5eBnsR9z+IH9o0lxvbWtaGh2E=; b=H3lZgdwX3aYZb7E4Xs6xBU2pDFHCgnVhSalH/0/A4aN+zCqDkxgqNmh15PgAYPc/c1s6/X 9iRxBYraR2S6ihkPXaGVDqZscogLW+ErTpsdQE1QlwjfuRQPkqWGdcYkT4jOvB/KPOBEHa aR1VA3lD+RoQg028Vb4H4gsNkzQL9gE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-694-L211E0ivPEKryiY6MgWcMg-1; Tue, 19 Mar 2024 11:59:03 -0400 X-MC-Unique: L211E0ivPEKryiY6MgWcMg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8AFE5800264; Tue, 19 Mar 2024 15:59:03 +0000 (UTC) Received: from localhost (unknown [10.42.28.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 58E6E202451F; Tue, 19 Mar 2024 15:59:03 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] libstdc++: Constrain std::vector default constructor [PR113841] Date: Tue, 19 Mar 2024 15:57:32 +0000 Message-ID: <20240319155858.3406992-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.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_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE, URI_HEX 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.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 This fixes the problem in the PR, which is revealed by the new concept-based constraints on std::pair constructors in C++20 mode. That makes this a C++20 regression, as the PR's example compiles with C++17. We need something similar for std::basic_string too, which I'll do later. Any comments? Tested aarch64-linux. -- >8 -- 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. --- libstdc++-v3/include/bits/allocator.h | 3 ++ libstdc++-v3/include/bits/stl_bvector.h | 3 ++ libstdc++-v3/include/bits/stl_vector.h | 3 ++ .../23_containers/vector/cons/113841.cc | 34 +++++++++++++++++++ 4 files changed, 43 insertions(+) create mode 100644 libstdc++-v3/testsuite/23_containers/vector/cons/113841.cc diff --git a/libstdc++-v3/include/bits/allocator.h b/libstdc++-v3/include/bits/allocator.h index ff4f5b9137b..9e75b37fce7 100644 --- a/libstdc++-v3/include/bits/allocator.h +++ b/libstdc++-v3/include/bits/allocator.h @@ -254,6 +254,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { public: typedef _Tp value_type; + allocator() { } template allocator(const allocator<_Up>&) { } }; @@ -262,6 +263,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { public: typedef _Tp value_type; + allocator() { } template allocator(const allocator<_Up>&) { } }; @@ -270,6 +272,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 a3343d95b36..d567e26f4e4 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 a8d387f40a1..31169711a48 100644 --- a/libstdc++-v3/include/bits/stl_vector.h +++ b/libstdc++-v3/include/bits/stl_vector.h @@ -135,6 +135,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); +}