[committed] libstdc++: Use direct-initialization for std::vector<bool>'s allocator [PR115854]

Message ID 20240710210735.906812-1-jwakely@redhat.com
State New
Headers
Series [committed] libstdc++: Use direct-initialization for std::vector<bool>'s allocator [PR115854] |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 warning Patch is already merged
linaro-tcwg-bot/tcwg_gcc_check--master-arm warning Patch is already merged

Commit Message

Jonathan Wakely July 10, 2024, 9:06 p.m. UTC
  Tested x86_64-linux. Pushed to trunk. Backports could follow.

-- >8 --

The consensus in the standard committee is that this change shouldn't be
necessary, and the Allocator requirements should require conversions
between rebound allocators to be implicit. But we can make it work for
now anyway.

libstdc++-v3/ChangeLog:

	PR libstdc++/115854
	* include/bits/stl_bvector.h (_Bvector_base): Convert allocator
	to rebound type explicitly.
	* testsuite/23_containers/vector/allocator/115854.cc: New test.
	* testsuite/23_containers/vector/bool/allocator/115854.cc: New test.
---
 libstdc++-v3/include/bits/stl_bvector.h                |  2 +-
 .../testsuite/23_containers/vector/allocator/115854.cc | 10 ++++++++++
 .../23_containers/vector/bool/allocator/115854.cc      | 10 ++++++++++
 3 files changed, 21 insertions(+), 1 deletion(-)
 create mode 100644 libstdc++-v3/testsuite/23_containers/vector/allocator/115854.cc
 create mode 100644 libstdc++-v3/testsuite/23_containers/vector/bool/allocator/115854.cc
  

Patch

diff --git a/libstdc++-v3/include/bits/stl_bvector.h b/libstdc++-v3/include/bits/stl_bvector.h
index 8685cc64cc4..245e1c3b3a7 100644
--- a/libstdc++-v3/include/bits/stl_bvector.h
+++ b/libstdc++-v3/include/bits/stl_bvector.h
@@ -654,7 +654,7 @@  _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 
       _GLIBCXX20_CONSTEXPR
       _Bvector_base(const allocator_type& __a)
-      : _M_impl(__a) { }
+      : _M_impl(_Bit_alloc_type(__a)) { }
 
 #if __cplusplus >= 201103L
       _Bvector_base(_Bvector_base&&) = default;
diff --git a/libstdc++-v3/testsuite/23_containers/vector/allocator/115854.cc b/libstdc++-v3/testsuite/23_containers/vector/allocator/115854.cc
new file mode 100644
index 00000000000..6c9016b311f
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/vector/allocator/115854.cc
@@ -0,0 +1,10 @@ 
+// { dg-do compile { target c++11 } }
+
+#include <vector>
+#include <testsuite_allocator.h>
+
+__gnu_test::ExplicitConsAlloc<int> alloc;
+std::vector<int, __gnu_test::ExplicitConsAlloc<int>> v;
+std::vector<int, __gnu_test::ExplicitConsAlloc<int>> v1(alloc);
+std::vector<int, __gnu_test::ExplicitConsAlloc<int>> v2(v1, alloc);
+std::vector<int, __gnu_test::ExplicitConsAlloc<int>> v3(std::move(v1), alloc);
diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/allocator/115854.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/allocator/115854.cc
new file mode 100644
index 00000000000..14b28cc3e96
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/vector/bool/allocator/115854.cc
@@ -0,0 +1,10 @@ 
+// { dg-do compile { target c++11 } }
+
+#include <vector>
+#include <testsuite_allocator.h>
+
+__gnu_test::ExplicitConsAlloc<bool> alloc;
+std::vector<bool, __gnu_test::ExplicitConsAlloc<bool>> v;
+std::vector<bool, __gnu_test::ExplicitConsAlloc<bool>> v1(alloc);
+std::vector<bool, __gnu_test::ExplicitConsAlloc<bool>> v2(v1, alloc);
+std::vector<bool, __gnu_test::ExplicitConsAlloc<bool>> v3(std::move(v1), alloc);