]> gcc.gnu.org Git - gcc.git/commitdiff
libstdc++: Begin lifetime of storage in std::vector<bool> [PR114367]
authorJonathan Wakely <jwakely@redhat.com>
Mon, 18 Mar 2024 13:00:17 +0000 (13:00 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 19 Mar 2024 15:13:18 +0000 (15:13 +0000)
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

index 2c8b892b07a43f886105fafa9dda3956314336e0..a3343d95b368b5fabe6d62fb38ad8f4d0960ea57 100644 (file)
@@ -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;
       }
This page took 0.063077 seconds and 5 git commands to generate.