From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 3D9963858D37; Tue, 19 Mar 2024 15:14:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3D9963858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1710861246; bh=vNsa0SiqmI6N+K5XjxPxTbruMPMSUHXgsW2tlB5B8VU=; h=From:To:Subject:Date:From; b=bIo61OnQKUkfajfptecOvYQPX6RrRbGiKE35T8YJ94xRCCf8X9urUAQtLiBc+tW+O xuV9yLFTO188NNNUj1A2H/RjMVOIdP166PrhyEWShSw/Z/l1Z+Lu6Nw7zwiz4xVpHu tDG2xFGCAWIOOHWemJfShhUA07IcqW3vOwZjix8o= 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 r14-9545] libstdc++: Begin lifetime of storage in std::vector [PR114367] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: c7a774edbf802d79b95871ede5b80f6e9adf8e88 X-Git-Newrev: 16afbd9c9c4282d56062cef95e6eccfdcf3efe03 Message-Id: <20240319151406.3D9963858D37@sourceware.org> Date: Tue, 19 Mar 2024 15:14:06 +0000 (GMT) List-Id: https://gcc.gnu.org/g:16afbd9c9c4282d56062cef95e6eccfdcf3efe03 commit r14-9545-g16afbd9c9c4282d56062cef95e6eccfdcf3efe03 Author: Jonathan Wakely Date: Mon Mar 18 13:00:17 2024 +0000 libstdc++: Begin lifetime of storage in std::vector [PR114367] This doesn't cause a problem with GCC, but Clang correctly diagnoses a bug in the code. The objects in the allocated storage need to begin their lifetime before we start using them. This change uses the allocator's construct function instead of using std::construct_at directly, in order to support fancy pointers. libstdc++-v3/ChangeLog: PR libstdc++/114367 * include/bits/stl_bvector.h (_M_allocate): Use allocator's construct function to begin lifetime of words. Diff: --- libstdc++-v3/include/bits/stl_bvector.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libstdc++-v3/include/bits/stl_bvector.h b/libstdc++-v3/include/bits/stl_bvector.h index 2c8b892b07a..a3343d95b36 100644 --- a/libstdc++-v3/include/bits/stl_bvector.h +++ b/libstdc++-v3/include/bits/stl_bvector.h @@ -674,13 +674,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _M_allocate(size_t __n) { _Bit_pointer __p = _Bit_alloc_traits::allocate(_M_impl, _S_nword(__n)); -#if __cpp_lib_is_constant_evaluated +#if __cpp_lib_is_constant_evaluated && __cpp_constexpr_dynamic_alloc if (std::is_constant_evaluated()) - { - __n = _S_nword(__n); - for (size_t __i = 0; __i < __n; ++__i) - __p[__i] = 0ul; - } + { + __n = _S_nword(__n); + for (size_t __i = 0; __i < __n; ++__i) + std::construct_at(std::to_address(__p) + __i); + } #endif return __p; }