public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-8568] libstdc++: Begin lifetime of storage in std::vector<bool> [PR114367]
@ 2024-04-03 10:46 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2024-04-03 10:46 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

https://gcc.gnu.org/g:d8d71b19f0b1e28fd6d413a6874ec55c568865b0

commit r13-8568-gd8d71b19f0b1e28fd6d413a6874ec55c568865b0
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Mar 18 13:00:17 2024 +0000

    libstdc++: Begin lifetime of storage in std::vector<bool> [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.
    
    (cherry picked from commit 16afbd9c9c4282d56062cef95e6eccfdcf3efe03)

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 64f04c1f4f5..8b54292e51b 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;
       }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-04-03 10:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-03 10:46 [gcc r13-8568] libstdc++: Begin lifetime of storage in std::vector<bool> [PR114367] Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).