From patchwork Wed Oct 2 19:37:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1992163 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=dF1OnVWI; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4XJm5K41Wnz1xtY for ; Thu, 3 Oct 2024 06:05:41 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D63BF3861039 for ; Wed, 2 Oct 2024 20:05:38 +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 ADE473858D34 for ; Wed, 2 Oct 2024 20:05:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ADE473858D34 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 ADE473858D34 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=1727899513; cv=none; b=ApnEiTnIBY54i8N5F9LFrlxztWTt7FXgvUes4wFz4GkJjbM+9RzLVpGqqcbayk6KVHwd2x2xaBf9/Ayew7cX62L36QmUaajhB0y6TY6upeQQlL5VrNSbv7IRBKRPggX5bkSOWy7WkiZvI/7eA7Yw9lgrnUpMFp2lU5U0sneg/tI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727899513; c=relaxed/simple; bh=C2E9eV6F59Y3e8VifA0uV5U60vvY/tivXsoFtGa3gX8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=bo6a10+9da8x0cCtJIbQ6SlkjJEmIkCkoP1/OAQg2uTFLEQVBPjFPDYbgolVNR8K+yPzH4uVztTdgmWC+THAZ8o8eAfrL/mghE8HE1/z81R6eNvOzLdoq+7LR499VYkTMmhN2S3UFMm6CcBlsz4bmozLiGDt/QKxYxgduMg6KpE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727899509; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=1aSPzywGQTirD6VgrtlrFeGEhaN4YgC+6TMcsTEdQ2E=; b=dF1OnVWI4DNW6AqsbFX54RCoazRn1h4faQ38W96BXyNwLbhI6wDdGGKaPRxiASapA49Zdu FWrKWzOj5nmSDt4EypXL4decjFLmEeimCnlqQpnishCVDcwy+QvwzIK179dt+sslsJaZUA bEh072nwVcdyi3zeoXT6+S6jd003q2w= Received: from mx-prod-mc-01.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-657-FyIhMIAfMHSndWM1Aqw2ww-1; Wed, 02 Oct 2024 16:05:08 -0400 X-MC-Unique: FyIhMIAfMHSndWM1Aqw2ww-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 50B10195608F; Wed, 2 Oct 2024 20:05:07 +0000 (UTC) Received: from localhost (unknown [10.42.28.136]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 97D781956088; Wed, 2 Oct 2024 20:05:05 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Cc: Jason Merrill Subject: [PATCH 1/2] libstdc++: Make std::construct_at support arrays (LWG 3436) Date: Wed, 2 Oct 2024 20:37:50 +0100 Message-ID: <20241002200503.3359969-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 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_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP 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 Is the g++ test change OK? Tested x86_64-linux. -- >8 -- The issue was approved at the recent St. Louis meeting, requiring support for bounded arrays, but only without arguments to initialize the array elements. libstdc++-v3/ChangeLog: * include/bits/stl_construct.h (construct_at): Support array types (LWG 3436). * testsuite/20_util/specialized_algorithms/construct_at/array.cc: New test. * testsuite/20_util/specialized_algorithms/construct_at/array_neg.cc: New test. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/initlist-opt1.C: Adjust for different diagnostics from std::construct_at by adding -fconcepts-diagnostics-depth=2. --- gcc/testsuite/g++.dg/cpp0x/initlist-opt1.C | 1 + libstdc++-v3/include/bits/stl_construct.h | 20 +++++++-- .../construct_at/array.cc | 41 +++++++++++++++++++ .../construct_at/array_neg.cc | 19 +++++++++ 4 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/specialized_algorithms/construct_at/array.cc create mode 100644 libstdc++-v3/testsuite/20_util/specialized_algorithms/construct_at/array_neg.cc diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-opt1.C b/gcc/testsuite/g++.dg/cpp0x/initlist-opt1.C index 391b7c47d50..38c4f00cec0 100644 --- a/gcc/testsuite/g++.dg/cpp0x/initlist-opt1.C +++ b/gcc/testsuite/g++.dg/cpp0x/initlist-opt1.C @@ -1,5 +1,6 @@ // PR c++/110102 // { dg-do compile { target c++11 } } +// { dg-additional-options "-fconcepts-diagnostics-depth=2" { target c++20 } } // { dg-skip-if "requires hosted libstdc++ for list" { ! hostedlib } } // { dg-error "deleted|construct_at" "" { target *-*-* } 0 } diff --git a/libstdc++-v3/include/bits/stl_construct.h b/libstdc++-v3/include/bits/stl_construct.h index dc08fb7ea33..146ea14e99a 100644 --- a/libstdc++-v3/include/bits/stl_construct.h +++ b/libstdc++-v3/include/bits/stl_construct.h @@ -90,11 +90,25 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cpp_constexpr_dynamic_alloc // >= C++20 template - constexpr auto + requires (!is_unbounded_array_v<_Tp>) + && requires { ::new((void*)0) _Tp(std::declval<_Args>()...); } + constexpr _Tp* construct_at(_Tp* __location, _Args&&... __args) noexcept(noexcept(::new((void*)0) _Tp(std::declval<_Args>()...))) - -> decltype(::new((void*)0) _Tp(std::declval<_Args>()...)) - { return ::new((void*)__location) _Tp(std::forward<_Args>(__args)...); } + { + void* __loc = const_cast*>(__location); + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 3436. std::construct_at should support arrays + if constexpr (is_array_v<_Tp>) + { + static_assert(sizeof...(_Args) == 0, "std::construct_at for array " + "types must not use any arguments to initialize the " + "array"); + return ::new(__loc) _Tp[1](); + } + else + return ::new(__loc) _Tp(std::forward<_Args>(__args)...); + } #endif // C++20 #endif// C++17 diff --git a/libstdc++-v3/testsuite/20_util/specialized_algorithms/construct_at/array.cc b/libstdc++-v3/testsuite/20_util/specialized_algorithms/construct_at/array.cc new file mode 100644 index 00000000000..c3683462835 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/specialized_algorithms/construct_at/array.cc @@ -0,0 +1,41 @@ +// { dg-do compile { target c++20 } } + +// LWG 3436. std::construct_at should support arrays + +#include +#include + +constexpr void +test_array() +{ + int arr[1] { 99 }; + std::construct_at(&arr); + VERIFY( arr[0] == 0 ); + + union U { + long long x; + int arr[4]; + } u; + u.x = -1; + + auto p = std::construct_at(&u.arr); + VERIFY( (*p)[0] == 0 ); + VERIFY( (*p)[1] == 0 ); + VERIFY( (*p)[2] == 0 ); + VERIFY( (*p)[3] == 0 ); + + struct NonTrivial { + constexpr NonTrivial() : i(99) { } + int i; + }; + + union U2 { + char c = 'a'; + NonTrivial arr[2]; + } u2; + + auto p2 = std::construct_at(&u2.arr); + VERIFY( (*p2)[0].i == 99 ); +} + +static_assert( [] { test_array(); return true; }() ); diff --git a/libstdc++-v3/testsuite/20_util/specialized_algorithms/construct_at/array_neg.cc b/libstdc++-v3/testsuite/20_util/specialized_algorithms/construct_at/array_neg.cc new file mode 100644 index 00000000000..deb86930d1a --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/specialized_algorithms/construct_at/array_neg.cc @@ -0,0 +1,19 @@ +// { dg-do compile { target c++20 } } + +// LWG 3436. std::construct_at should support arrays + +#include + +void +test_array_args() +{ + int arr[2]; + std::construct_at(&arr, 1, 2); // { dg-error "here" } + // { dg-error "must not use any arguments" "" { target *-*-* } 0 } +} + +void +test_unbounded_array(int (*p)[]) +{ + std::construct_at(p); // { dg-error "no matching function" } +} From patchwork Wed Oct 2 19:37:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1992164 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=GQSCRaSh; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4XJm5y026Bz1xtY for ; Thu, 3 Oct 2024 06:06:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D6C6D385C6D3 for ; Wed, 2 Oct 2024 20:06:11 +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 ESMTP id F18C63858C50 for ; Wed, 2 Oct 2024 20:05:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F18C63858C50 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 F18C63858C50 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=1727899515; cv=none; b=EW2INXQcnvTGPyU8y9F7+tNO5SBO+KQ4H9Ie7RXDzIcFUBDM+GJv/7t0BHNerLI/+mifFRQ2GCnmZ37LkTOS8fw+6+b0UsP+XAyAWcb8PLi62G/7AClsy2B7s2tsy2WxHQCATB9rB1VT3j77OjwEjPUQHe0zJzwXjdLQVC1tJlM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727899515; c=relaxed/simple; bh=x3SUyvx8z5vRf3NNKlEMTgvEh8Ajm9mwL7D0VTsuehU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=heN1aYfMPP4RINCMsJmS8xER/Lzh9DmboXkbXbWJsg65iHqGapCNLATse2Z0EwqifOf0+j4Hh9tVxoqkl4RSIaGo9SgiDgy+BfwdKhHeRWcTy7F3J1NgoMaAE2qyq0slmudvil7fZcjlNqFG37fQ7wyKdmB1N4zSRaD/kAPiZY0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727899513; 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: in-reply-to:in-reply-to:references:references; bh=2kFMnEwWw7QlfAjPHBSLIUcyWvScpZJb3dQqkKwGf/s=; b=GQSCRaShSANz3gcYXXJRDJ6JL6nq2Qed1sphK8kQLdtsxgcieyYqj12QVftkxi8nY1fAew hY1CaGB0XgSOFluIAAV5nAUzI7f0HTWzlskWVFhWV43L4OEILzPhHIFGBwZVHQRN1cA7xG W/sXX7ZDuC55MYGX16Q+Stla6I8MNmA= 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-570-L5JfyH5fNVeqvhVEbWWOuA-1; Wed, 02 Oct 2024 16:05:10 -0400 X-MC-Unique: L5JfyH5fNVeqvhVEbWWOuA-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 788D21955F45; Wed, 2 Oct 2024 20:05:09 +0000 (UTC) Received: from localhost (unknown [10.42.28.136]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D17AD19560A3; Wed, 2 Oct 2024 20:05:08 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH 2/2] libstdc++: Do not cast away const-ness in std::construct_at (LWG 3870) Date: Wed, 2 Oct 2024 20:37:51 +0100 Message-ID: <20241002200503.3359969-2-jwakely@redhat.com> In-Reply-To: <20241002200503.3359969-1-jwakely@redhat.com> References: <20241002200503.3359969-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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_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. -- >8 -- This change also requires implementing the proposed resolution of LWG 3216 so that std::make_shared and std::allocate_shared still work, and the proposed resolution of LWG 3891 so that std::expected still works. libstdc++-v3/ChangeLog: * include/bits/shared_ptr_base.h: Remove cv-qualifiers from type managed by _Sp_counted_ptr_inplace, as per LWG 3210. * include/bits/stl_construct.h: Do not cast away cv-qualifiers when passing pointer to placement new. * include/std/expected: Use remove_cv_t for union member, as per LWG 3891. * testsuite/20_util/allocator/void.cc: Do not test construction via const pointer. --- libstdc++-v3/include/bits/shared_ptr_base.h | 15 ++++++++------- libstdc++-v3/include/bits/stl_construct.h | 6 +++--- libstdc++-v3/include/std/expected | 2 +- libstdc++-v3/testsuite/20_util/allocator/void.cc | 15 --------------- 4 files changed, 12 insertions(+), 26 deletions(-) diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h index 3d0b74ba1c6..ef0658f6182 100644 --- a/libstdc++-v3/include/bits/shared_ptr_base.h +++ b/libstdc++-v3/include/bits/shared_ptr_base.h @@ -591,7 +591,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Alloc& _M_alloc() noexcept { return _A_base::_S_get(*this); } - __gnu_cxx::__aligned_buffer<_Tp> _M_storage; + __gnu_cxx::__aligned_buffer<__remove_cv_t<_Tp>> _M_storage; }; public: @@ -633,7 +633,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION virtual void* _M_get_deleter(const std::type_info& __ti) noexcept override { - auto __ptr = const_cast::type*>(_M_ptr()); // Check for the fake type_info first, so we don't try to access it // as a real type_info object. Otherwise, check if it's the real // type_info for this class. With RTTI enabled we can check directly, @@ -646,11 +645,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Sp_make_shared_tag::_S_eq(__ti) #endif ) - return __ptr; + return _M_ptr(); return nullptr; } - _Tp* _M_ptr() noexcept { return _M_impl._M_storage._M_ptr(); } + __remove_cv_t<_Tp>* + _M_ptr() noexcept { return _M_impl._M_storage._M_ptr(); } _Impl _M_impl; }; @@ -674,13 +674,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION [[no_unique_address]] _Alloc _M_alloc; union { - _Tp _M_obj; + remove_cv_t<_Tp> _M_obj; char _M_unused; }; friend class __shared_count<_Lp>; // To be able to call _M_ptr(). - _Tp* _M_ptr() noexcept { return std::__addressof(_M_obj); } + auto _M_ptr() noexcept { return std::__addressof(_M_obj); } public: using __allocator_type = __alloc_rebind<_Alloc, _Sp_counted_ptr_inplace>; @@ -962,7 +962,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __shared_count(_Tp*& __p, _Sp_alloc_shared_tag<_Alloc> __a, _Args&&... __args) { - typedef _Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp> _Sp_cp_type; + using _Tp2 = __remove_cv_t<_Tp>; + using _Sp_cp_type = _Sp_counted_ptr_inplace<_Tp2, _Alloc, _Lp>; typename _Sp_cp_type::__allocator_type __a2(__a._M_a); auto __guard = std::__allocate_guarded(__a2); _Sp_cp_type* __mem = __guard.get(); diff --git a/libstdc++-v3/include/bits/stl_construct.h b/libstdc++-v3/include/bits/stl_construct.h index 146ea14e99a..9d6111396e1 100644 --- a/libstdc++-v3/include/bits/stl_construct.h +++ b/libstdc++-v3/include/bits/stl_construct.h @@ -96,7 +96,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION construct_at(_Tp* __location, _Args&&... __args) noexcept(noexcept(::new((void*)0) _Tp(std::declval<_Args>()...))) { - void* __loc = const_cast*>(__location); + void* __loc = __location; // _GLIBCXX_RESOLVE_LIB_DEFECTS // 3436. std::construct_at should support arrays if constexpr (is_array_v<_Tp>) @@ -130,7 +130,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return; } #endif - ::new((void*)__p) _Tp(std::forward<_Args>(__args)...); + ::new(static_cast(__p)) _Tp(std::forward<_Args>(__args)...); } #else template @@ -146,7 +146,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template inline void _Construct_novalue(_T1* __p) - { ::new((void*)__p) _T1; } + { ::new(static_cast(__p)) _T1; } template _GLIBCXX20_CONSTEXPR void diff --git a/libstdc++-v3/include/std/expected b/libstdc++-v3/include/std/expected index 9e92339e406..d4a4bc17541 100644 --- a/libstdc++-v3/include/std/expected +++ b/libstdc++-v3/include/std/expected @@ -1261,7 +1261,7 @@ namespace __expected { } union { - _Tp _M_val; + remove_cv_t<_Tp> _M_val; _Er _M_unex; }; diff --git a/libstdc++-v3/testsuite/20_util/allocator/void.cc b/libstdc++-v3/testsuite/20_util/allocator/void.cc index e50bf993294..04cd2094776 100644 --- a/libstdc++-v3/testsuite/20_util/allocator/void.cc +++ b/libstdc++-v3/testsuite/20_util/allocator/void.cc @@ -88,23 +88,8 @@ static_assert( std::is_same::const_pointer, const void*>(), "const_pointer is const void*" ); #endif // C++20 -void -test02() -{ - std::allocator av; - int* p = std::allocator().allocate(1); - const int* c = p; - std::allocator_traits>::construct(av, c, 0); - volatile int* v = p; - std::allocator_traits>::construct(av, v, 0); - const volatile int* cv = p; - std::allocator_traits>::construct(av, cv, 0); - std::allocator().deallocate(p, 1); -} - int main() { test01(); - test02(); }