aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2024-03-18 13:00:17 +0000
committerJonathan Wakely <jwakely@redhat.com>2024-06-11 13:18:07 +0100
commit5c2c5805304da2436f4a749d357eee34eae9d792 (patch)
tree61940dc4846511438f33106bfbb11977c575b71c
parent80d0f82e6961ff8991897454e2bac126488ea6b9 (diff)
downloadgcc-5c2c5805304da2436f4a749d357eee34eae9d792.zip
gcc-5c2c5805304da2436f4a749d357eee34eae9d792.tar.gz
gcc-5c2c5805304da2436f4a749d357eee34eae9d792.tar.bz2
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)
-rw-r--r--libstdc++-v3/include/bits/stl_bvector.h12
1 files changed, 6 insertions, 6 deletions
diff --git a/libstdc++-v3/include/bits/stl_bvector.h b/libstdc++-v3/include/bits/stl_bvector.h
index f90d3c4..e1559c2 100644
--- a/libstdc++-v3/include/bits/stl_bvector.h
+++ b/libstdc++-v3/include/bits/stl_bvector.h
@@ -629,13 +629,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;
}