From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id E326C3858CDB for ; Tue, 19 Mar 2024 15:14:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E326C3858CDB 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 E326C3858CDB 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=1710861275; cv=none; b=unZnOYrMGqu7//V+MO0HTfhI2Htcll/GJkTS4wj+WIBTDft5kFoGb6E1Z6WGBijhdEFGd0U64+ta2gTxmel5Vh7F7fm2zSNxP9TNNLg/plYyUXpPQi7/ybTX5exJ2R3xOO0xuJBIlcnkV1aUae0zttuYCs9qiWtsPe54kMf+MA4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710861275; c=relaxed/simple; bh=XaxH18fWh7pOvXOpe3Qj+heBGc3PcuYVpOSM048BCUA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=wdp2h7w2JfMdu5qEDaet8jZpSDJWB1y4WIjFdATQrfu9b8c7MAa+py+0N4aWaVsTjnJqNkkLtvbKEOHvMc3nblmO0026Oc2E3uLQBkB0FNWLyLANX6YF0V4YygYzzMRhfLO5IUdydowj2rwH93B85Qq+d0Flqjzl9m6/pzvQ1sg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710861273; 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=ZgSz0juDyeZuqLPlm2EC7/w+71AO7sAUiMBYeVqaRwc=; b=TDERwLjeoPc6/tvUkFaqlvlGtmVkv7a2X+cum2xhwyugIHVexg1feQiV7VUStYMCTi0ngR sigtFGo76RFl77pOjhMDgj/ajsO7YyPS08OQ/avVS1NFedeaOIzhAi7FqtoGhn6M2TyH8B KKMmO4DxCrgB8MAPPP++E1EsQRnhCF0= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-149-0u-GEck3PfuVGu0X5IP2OA-1; Tue, 19 Mar 2024 11:14:30 -0400 X-MC-Unique: 0u-GEck3PfuVGu0X5IP2OA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 423841C0042C; Tue, 19 Mar 2024 15:14:29 +0000 (UTC) Received: from localhost (unknown [10.42.28.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F0D617A91; Tue, 19 Mar 2024 15:14:28 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Begin lifetime of storage in std::vector [PR114367] Date: Tue, 19 Mar 2024 15:14:06 +0000 Message-ID: <20240319151424.3382794-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.3 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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Tested x86_64-linux. Pushed to trunk. Backport to gcc-13 to follow. -- >8 -- 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. --- 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; } -- 2.44.0