From 75df481fcc381d6aaefdbe2ef1d66927e30b5743 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Fri, 21 Mar 2025 22:49:44 +0000 Subject: [PATCH] libstdc++: Ensure that std::vector allocator has bool value_type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is the subject of LWG 4228 which notes that libstdc++ doesn't enforce this requirement. That's just a bug because I forgot to add it to vector when adding it elsewhere. For consistency with the other containers we should not allow incorrect allocator types for strict -std=c++NN modes, but it is very late to make that change for GCC 15 so this only enables the assertion for C++20 (where it's required). For GCC 16 we can enable it for strict modes too. libstdc++-v3/ChangeLog: * include/bits/stl_bvector.h (vector): Enforce the C++20 requirement that the allocator's value_type matches the container. * testsuite/23_containers/vector/bool/cons/from_range.cc: Fix incorrect allocator type. Reviewed-by: Tomasz KamiƄski --- libstdc++-v3/include/bits/stl_bvector.h | 4 ++++ .../testsuite/23_containers/vector/bool/cons/from_range.cc | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/bits/stl_bvector.h b/libstdc++-v3/include/bits/stl_bvector.h index 2292eec54ad..3ee15eaa938 100644 --- a/libstdc++-v3/include/bits/stl_bvector.h +++ b/libstdc++-v3/include/bits/stl_bvector.h @@ -751,6 +751,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER #if __cplusplus >= 201103L friend struct std::hash; +# if __cplusplus > 201703L // || defined __STRICT_ANSI__ + static_assert(is_same::value, + "std::vector must have the same value_type as its allocator"); +# endif #endif public: diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/cons/from_range.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/cons/from_range.cc index f531e7f5039..37f0ecf32ad 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/bool/cons/from_range.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/cons/from_range.cc @@ -71,7 +71,7 @@ test_ranges() bool val; }; using rvalue_input_range = test_range; - do_test(std::allocator()); + do_test(std::allocator()); return true; }